Random number generators

Chris Kelleher

Administrator
Staff member
How Random Numbers are generated in Progress using the -rand 2 parameter, by Gus Bjorklund

------------------
Chris Schreiber
ProgressTalk.com Manager
chris@fast4gl.com
 

Chris Kelleher

Administrator
Staff member
>> Does anybody know how to create your own random generator and link it to
>> Client session?> > Why would you want to?>
> Creating a random number generator is not easy. Actually it isn't
> possible with just software -- John Von Neumann, Patron Saint of
> Programmers, summed it up quite nicely in 1951:>
> Anyone who considers arithmetical methods of producing
> random digits is, of course, in a state of sin.>
> Progress has 2 (psuedo) random number generators. The default has the
> property of always repeating its cycle. The one choosen with -rand 2
> does not repeat.>
Actually it does repeat, but not often enough to matter much. Here is more
info than anyone needs to know. The -rand 2 generator is very good and
should be sufficient for most purposes.
The algorithm it uses is what is called a "linear congruential pseudorandom
number generator". It has a period of 2147483647, after which it repeats the
same sequence of numbers.
The starting "seed" value determines the first value it generates.
Subsequent values are derived from the previous value.
The starting seed value is set when the random number generator is first
called in a session. It is derived from the time() function which gives
seconds since 00:00:00 jan 1 1970.The algorithm is
seed = (16807 * seed) mod 2147483647 random = seed
See CACM Oct 1988 pp 1192 - 1201 for more details.
You can write variations of this algorithm, but read the article first.
Getting it right is tricky because you have to pick good numbers to use in
place of 16807 and the modulus. Dealing with integer overflow correctly in
the multiplication is necessary.-- regards,
Gus Bjorklund, Wizard, Progress Software Corporation
"Work is the greatest thing in the world so we should always save some of it
for tomorrow."
 
Top