[fpc-pascal] Better random numbers ?

Jeff Miller miller at psy.otago.ac.nz
Mon Feb 27 00:09:08 CET 2006

> Hi, I am using standard run of the mill randomize/random() calls in a program 
> to generate random numbers, used in turn to select random data which is fed 
> into another program.

You are just supposed to call randomize once, to initialize the random
number generator.  You then call random over and over, and a different
random number gets generated from each successive call.  The random
call modifies the stored seed so that repeated calls give different answers.
I can see how this might not work so well when you are calling the
program over and over again (i.e., restarting it).

One option is to have the random # generator program generate a large
batch of numbers that are saved to a file, and you only call it again when
the calling program has used up that batch.  (If you are working in windows,
you might look at the randgen program, freely available at 
which can be used like this.)

Another option is to have the random # generator program return its
new seed value as well as its random number.  When you call it again,
you pass it the seed value that it last returned, and the random #
generator program sets the seed to that value without calling randomize

I hope something here useful to you... 

miller at psy.otago.ac.nz

More information about the fpc-pascal mailing list