[fpc-pascal] Re: Random numbers

Vinzent Hoefler JeLlyFish.software at gmx.net
Mon Mar 6 15:28:31 CET 2006


On Monday 06 March 2006 12:37, Antal wrote:

> > The Mersenne Twister Free Pascal uses is one of the best PRNGs
> > known today, it just has to be used the right way. But calling it
> > from several threads and "randomly" overwriting its state array is
> > definitely not the right way to use it.
>
> I'm disappointed, because I compiled the following program (on
> linux): rnd.pp
> begin
> Randomize;
> writeln(random(394));
> end.

Again: You are using a PRNG the wrong way, Jonas already pointed that 
out.

Randomize is supposed to be called exactly once and then never again and 
after then a (rather large) series of random number should be 
generated. The way you use it, by reinitializing a PRNG before each 
generation of a single random number, basically means all you get is 
the "entropy" of the randomizer (the system clock) and not the one of 
the PRNG. Well, last time I checked, the system clock is not exactly 
random.


Vinzent.




More information about the fpc-pascal mailing list