         Edinburgh IMP77 Compiler - Version 8.4

    1  !%endoflist
    2  !These Pseudo-random numbers were written by P. Reid.  It is not known if
    3  !they are genuinely random or not.
    4  
    5  !**  %routine   INITALISE RANDOM    sets up the random integer SEED          **!
    6  !**  %real %fn  RANDOM REAL (LO,HI) returns uniformly distributed reals      **!
    7  !**                                 between LO and HI inclusive              **!
    8  !**  %short %fn RANDOM INT (LO,HI)  returns uniformly distributed short      **!
    9  !**                                 integers between LO and HI inclusive     **!
   10  
   11  %own %integer Seed=0  {initialised to 0: JHB mod 16/12/86}
   12  
   13  
   14  %routine Initialise Random
   15  !
   16  ! Set up SEED
   17  !
   18     Seed = CpuTime
   19  %end
   20  
   21  
   22  %realfn Random Real(%real Lo, Hi)
   23  !
   24  ! Returns a random real between LO and HI inclusive
   25  !
   26     Seed = (23501*Seed + 6923) & 32767
   27     %result = Lo + (Seed * (Hi - Lo))/32767
   28  %end
   29  
   30  
   31  %shortfn Random Int (%short Lo, Hi)
   32  !
   33  ! Returns a random shortinteger between LO and HI inclusive
   34  !
   35     Seed = (23501*Seed + 6923) & 32767
   36     %result = Int(Lo + (Seed * (Hi - Lo))/32767)
   37  %end
   38  
   39  !%list
   40  %endoffile

   13 Statements compiled
