<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Tue, 13 Dec 1983 08:38:00 PST
From   : Eldridge.es@PARC-MAXC.ARPA
Subject: Re: RANDOM in Pascal

Try the following (I use it in JRT Pascal):

function Random(Seed : real): real;

{ Return the next value in a pseudo-random sequence.  The range is
0<=N<1. }

begin
  Seed := (9821.0 * Seed) + 0.211327;
  Seed := Seed - trunc(Seed);
  Random := Seed
end;  {Random}


Initialize the random number generator by giving it a first seed.
(RandNum and StartValue are both real)

  RandNum := Random(StartValue);

Succeeding numbers in the sequence are generated by:

  RandNum := Random(RandNum);


The formula used is:  NextSeed = frac((9821.0 * Seed) + 0.211327)
This is the formula in the HP-41C standard applications library.

George
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>