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 - 06:16:43 CEST

"Mike Warren" <miwa-not-this-bit@or-this-csas.net.au> wrote in message
news:4451913f$0$501$61c65585@uq-127creek-reader-03.brisbane.pipenetworks.com.au...
> Skybuck Flying wrote:
>> Delphi has a random function which looks like follows:
>>
>> function Random( aRange : integer ) : integer;
>>
>> The problem for me is that it only returns 32 bits... actually just
>> 31 bits.
>> Delphi has no unsigned 64 bit integer... so a signed 63 bit integer
>> for now will have to do...
>
> Can't you just use this?
>
> var
> I: Int64;
>
> I := Random($FFFFFFFF) * $100000000 + Random($FFFFFFFF);

Where does the parameter go in ?

It's missing ?

Variable I is supposed to be in the range 0 to Parameter-1

Nice idea though...

But it needs quite a lot of modification/work:

First the parameter has to be split up into two 32 bit words/integers.

Then the words can be randomized.

Then the result has to be put back into 64 bits...

I := Random( first 32 bits of parameter)
I := I * 2^32; // to shift the bits to the higher 32 bits.
I := I + Random( secondary 32 bits of parameter)

Finally I don't feel confident and the correctness of the code.

It will probably leave some offsets unused ?

On top of that... many possibilities for coding errors/troubles...

Shift errors, range check errors, signed problems, unsigned problems...
complex code.

Just to be able to use 64 bits.

Bad but interesting.

I will leave it at that.

It will probably not be possible to compare the output of this version with
the 64 bit version.

So another testing method will have to be used to check if all offsets are
actually possible.

Or one has to go about it in theory... to much work if you ask me ;)

I choose the path of reverse enginering and going with a modified 64 bit
version...

I think that will be faster and less error prone.

Only one instruction to go.

I wonder how the assembler applies the range limit, haven't understood that
yet when looking at the assembler.

Finally calling random twice and all these extra instructions is pushing my
performance patience a little bit =D

Bye,
  Skybuck.
Received on Mon May 1 02:05:25 2006