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:06:26 CEST

I think I have found the bug.

The modules must first be applied to the initial rand seed, since the
initial rand seed could be larger than the permitted range.

Then the next random number is calculated but no module is yet applied...
just to safe an instruction... then on the next call the modules is applied
again.

I hope this doesn't disturb the algorithm... otherwise the algorithm might
be flawed in the first place ;)

function LehmerRandom32bitSafe( ParaLehmerModulesMInt64 : int64 ) : int64;
begin
 if ParaLehmerModulesMInt64 > 0 then
 begin
  vLehmerRandSeedInt64 := vLehmerRandSeedInt64 mod ParaLehmerModulesMInt64;
  result := vLehmerRandSeedInt64;
  vLehmerRandSeedInt64 := vLehmerMultiplierAInt64 * vLehmerRandSeedInt64;
  vLehmerRandSeedInt64 := vLehmerRandSeedInt64 +
vLehmerAdditiveConstantCInt64;
 end else
 begin
  result := 0;
 end;
end;

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