Re: 63/64 bit version of Delphi's function random( aRange : integer ) : integer; ?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


sci.crypt archive

Re: 63/64 bit version of Delphi's function random( aRange : integer ) : integer; ?

From: Skybuck Flying <spam@hotmail.com>
Date: Fri Apr 28 2006 - 11:04:02 CEST

>> function Random64(Range: Int64): Int64;
>> var
>> H, L: Int64;
>> begin
>> H := Range and $FFFFFFFF00000000 div $100000000;
>> L := Range and $FFFFFFFF;
>> Result := H * $100000000 + L; // TEST - Remove
>> //Result := Random(H) * $100000000 + Random(L);
>> end;
>>
>> Call Random64(0) and it produces 0
>> Call Random64(High(Int64)) and it produces High(Int64) (7FFFFFFFFFFFFFFF)
>
> Ok these are nice extremes for 64 bit integers.
>
> But random works with signed integers and returns signed integers !
>
> That means the values that can be fed into random have to be limited to 31
> bits !
>
> Did you account for this ?
>
> I don't think so.
>
> I think your Random64 function will "bomb out" at some point causing a
> range check error.
>
> And as I already tried to explain in previous post but apperently it got
> cut out... but some people seemed to understand what I ment.
>
> The random function will only return positive integers !
>
> So the random function will only return 31 bits. Values up to 2 to the
> power of 31, minus 1.
>
> That means your random64 function has a bit missing at bit position 31 and
> bit position 63 when counting from bit position 0 to 63.
>
> Do you understand what I am trying to say ?
>
> Rendering 64 bit patterns onto the screen will clearly show a pattern.
>
> Vertical lines at bit position 31 and bit position 63 ;)
>
> I have not tested this but I feel confident a clear pattern will emerge.
>
> So the point of the story is: bad distribution.
>
> And in my case it means not all offsets are tested ;)
>
> Bye,
> Skybuck.

I must/like to add to the story:

I once read how assembler is bad because it's difficult to do bound/range
checking and mixing signed and unsigned integers is a pain and difficult.

You completely missed this signed bit issue thing which means you sure fit
the profile of somebody who programmed in assembler a lot and is kinda
sloppy with those things ? Am I right ? I wonder ? ;)

Bye,
  Skybuck =D
Received on Mon May 1 02:05:33 2006