RAND.DEF 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. DEFINITION MODULE Rand;
  2. FROM NumTypes IMPORT Real8;
  3. (* Random numbers generator.
  4. Algorithm : Based on the additive congruential method
  5. (Knuth, The art of computer programming, Vol.2, pp 26-27)
  6. *)
  7. PROCEDURE Randomize;
  8. (* Initializes the random number generator. The random number sequence
  9. following a call to Randomize cannot be reproduced.
  10. A call to Randomize is done automatically at the initialization
  11. of this module.
  12. *)
  13. PROCEDURE RandomInit (seed : CARDINAL);
  14. (* Initializes the random number generator.
  15. The 'seed' parameter is used to generate the first number of the
  16. sequence. Thus, following a call to RandomInit with a given seed,
  17. the random number sequence will always be the same, regardless of
  18. any previous call to Randomize, RandomCard, etc...
  19. Note: RandomCard, RandomInt, RandomReal are based on the same
  20. generator, so in order to get the same sequence, these functions
  21. must be called in the same order.
  22. *)
  23. PROCEDURE RandomCard (bound : CARDINAL) : CARDINAL;
  24. (* Returns a random cardinal in the range (0 <= r < bound) if bound is
  25. greater than 0, or in the range (0 <= r <= MaxCard) if bound = 0.
  26. *)
  27. PROCEDURE RandomInt (bound : INTEGER): INTEGER;
  28. (* Returns a random integer in the range (0 <= r < bound) if bound is
  29. greater than 0, or in the range (0 <= r <= MaxInt) if bound = 0.
  30. *)
  31. (*
  32. PROCEDURE RandomReal (): Real8;
  33. *) (* Returns a random real uniformly distributed the range (0.0 <= r < 1.0)
  34. with 15-16 decimal digits (IEEE double precision floating point numbers
  35. standard)
  36. *)
  37. END Rand.