home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pmos2002.zip / SRC / RANDOM.MOD < prev    next >
Text File  |  1996-06-25  |  2KB  |  51 lines

  1. IMPLEMENTATION MODULE Random;
  2.  
  3.         (********************************************************)
  4.         (*                                                      *)
  5.         (*              Random number generator                 *)
  6.         (*                                                      *)
  7.         (*  Programmer:         P. Moylan                       *)
  8.         (*  Last edited:        25 June 1996                    *)
  9.         (*  Status:             OK                              *)
  10.         (*                                                      *)
  11.         (********************************************************)
  12.  
  13. FROM RandCard IMPORT
  14.     (* const*)  modulus,
  15.     (* var  *)  seed,
  16.     (* proc *)  RandCardinal;
  17.  
  18. VAR scale: REAL;
  19.  
  20. (************************************************************************)
  21.  
  22. PROCEDURE RANDOM(): REAL;
  23.  
  24.     (* Returns a random number from a uniform (0.0, 1.0) distribution.  *)
  25.     (* This version relies on procedure RandCardinal to do the random   *)
  26.     (* number generation; all that we do is the scaling.                *)
  27.  
  28.     BEGIN
  29.         RETURN scale*FLOAT(RandCardinal());
  30.     END RANDOM;
  31.  
  32. (************************************************************************)
  33.  
  34. PROCEDURE Randomize (newseed: CARDINAL);
  35.  
  36.     (* Resets the seed of the random number generator.  *)
  37.  
  38.     BEGIN
  39.         IF newseed = 0 THEN newseed := 1
  40.         ELSIF newseed >= modulus THEN newseed := modulus-1
  41.         END (*IF*);
  42.         seed := newseed;
  43.     END Randomize;
  44.  
  45. (************************************************************************)
  46.  
  47. BEGIN
  48.     scale := 1.0/FLOAT(modulus);
  49. END Random.
  50. 
  51.