[fpc-pascal] Why is Random(255) some 529x slower compared to Delphi 7?

Dimitri Smits smitco at telenet.be
Wed Dec 7 19:26:35 CET 2011


----- "Jürgen Hestermann" <juergen.hestermann at gmx.de> schreef:


> But now we have a fast random() function in Delphi and a statistical 
> good one in FPC but none of them has both.


just my 2cts, but...


The Delphi 7 help states about "function System.Random [ ( Range: Integer) ];" the following
--
In Delphi code, Random returns a random number within the range 0 <= X < Range. If Range is not specified, the result is a real-type random number within the range

0 <= X < 1.

To initialize the random number generator, add a single call Randomize or assign a value to the RandSeed variable before making any calls to Random.

Note:	Because the implementation of the Random function may change between compiler versions, we do not recommend using Random for encryption or other purposes that require reproducible sequences of pseudo-random numbers.
--


I would argue that:
- using Random for encryption always was a bad idea
- you have largely incompatible implementations and expectations when you want to make code fpc+delphi7 compilable

As for other Random functions, Delphi7 also has Math.RandG (gaussian distribution around a mean) and Math.RandomRange. I would suggest the Math.RandomMT and a simpler, faster random method + good documenting.

The above Delphi-help snippet also discourages explicitly the use for encryption and other purposes. A "See also" could be used to get some statistically better distributed random numbers.

OR, what was suggested with the "pluggable" Random number generatorcall like the memorymanagers.

like I said, just my 2cts...

kind regards,
Dimitri Smits



More information about the fpc-pascal mailing list