RANDOM.DEF 1.1 KB

12345678910111213141516171819202122232425262728
  1. DEFINITION MODULE Random;
  2. (*
  3. Random number generator.
  4. Uses the 'Minimal standard random number generator' described by
  5. Park & Miller, CACM 31,10,Oct 88 p1192. The code has been checked
  6. for the 10001st random as specified in Park & Miller p1195.
  7. This version returns a REAL randomly distributed in the closed range
  8. [0.0,1.0], and will be correct if the real mantissa is 46 bits
  9. or larger (including sign bit). The sequence is guaranteed to produce
  10. all values of the form n/m for n = 0 to m, where m is 2147483646
  11. (=2**31-2), before cycling.
  12. *)
  13. PROCEDURE InitRandom (seed : REAL);
  14. (* Initialise the random number generator with the given seed. *)
  15. (* The seed should be in the range [1.0,2147483646.0] - values outside *)
  16. (* this range are clamped to the extreme values. *)
  17. (* If InitRandom is not called, the system clock is used to initialise *)
  18. (* the sequence; thus InitRandom must be called to create a *)
  19. (* reproducible sequence. *)
  20. (* InitRandom may be called as often as needed. *)
  21. PROCEDURE Random() : REAL;
  22. (* Return the next pseudo-random number in the closed range [0.0,1.0] *)
  23. END Random.
  24.