Re: Finally a safe and math accurate random64bit function ! ;)
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: Finally a safe and math accurate random64bit function ! ;)

From: Skybuck Flying <spam@hotmail.com>
Date: Sat Apr 29 2006 - 11:44:45 CEST

Well this faster bumps the speed from 1.5 MB/sec to 2.8 MB/sec still not too
great.

It can probably go faster still.

// faster version
function Random64bit( ParaRange : int64 ) : int64;
var
 vBit00ToBit15 : Int64;
 vBit16toBit31 : Int64;
 vBit32toBit47 : Int64;
 vBit48toBit63 : Int64;
begin

 // ....||||....|||| ....||||....||||
 vBit48ToBit63 := (ParaRange and $FFFF000000000000) shr 48;
 vBit32ToBit47 := (ParaRange and $0000FFFF00000000) shr 32;
 vBit16ToBit31 := (ParaRange and $00000000FFFF0000) shr 16;
 vBit00ToBit15 := (ParaRange and $000000000000FFFF);

 // ....||||....||||
 Result :=
  LehmerRandom32bitSafe( vBit48ToBit63 ) shl 48 +
  LehmerRandom32bitSafe( vBit32ToBit47 ) shl 32 +
  LehmerRandom32bitSafe( vBit16ToBit31 ) shl 16 +
  LehmerRandom32bitSafe( vBit00ToBit15 ) {* $0000000000000001};

 // used to test bitmasks *** must be enabled to
{
 Result :=
  vBit48ToBit63 * $0001000000000000 +
  vBit32ToBit47 * $0000000100000000 +
  vBit16ToBit31 * $0000000000010000 +
  vBit00ToBit15; // * $0000000000000001;
}

end;

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