home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / modula2 / library / queuem2 / unifrng.def < prev    next >
Text File  |  1989-08-31  |  4KB  |  107 lines

  1. (* source: h:\modula\defs\UnifRNG.DEF     v1.0a             revised: 88.07.18
  2.    author: G.Greene, AGCS D/429 (NS/TS), 312/681-7783       created: 88.07.18
  3.  
  4.    function:
  5.     This is the definition for a module which exports generators of
  6.     uniformly-distributed pseudo-random variates.  The primary procedure--
  7.     invoked, directly or indirectly, by all other random number generators--
  8.     provides reals in the half-open interval [0,1).  A specialized variant of
  9.     this generates values in the interval (0, 1), for applications wherein
  10.     zero values are not acceptable.  There are also discrete-uniform, general
  11.     continuous rectangular, and Pareto random number generators.  Procedures
  12.     are provided for reading and setting the random number seed value.
  13.  
  14.    history:
  15.     88.07.18  1.0a  initial release
  16. *)
  17.  
  18.  
  19. DEFINITION MODULE UnifRNG;
  20.  
  21.  
  22. (*  Return as the function value a Real value which is uniformly distributed
  23.     in the interval [0,1).
  24. *)
  25.  
  26. PROCEDURE  UniformVariate ( ): LONGREAL;
  27.  
  28.  
  29.  
  30.  
  31. (*  Since there is a chance, albeit minute, that the standard uniform random-
  32.     number generator will return a zero value, and since a zero value will
  33.     result in an error when used in some applications (particularly other
  34.     random variate generators), we provide this function that is guaranteed
  35.     not to yield a zero value.
  36. *)
  37.  
  38. PROCEDURE  NonzeroUniformVariate ( ): LONGREAL;
  39.  
  40.  
  41.  
  42. (*  Return as the function value a discrete uniform variate in the range
  43.     specified by the parameters.  The parameters are supposed to be the low
  44.     and high ends of the range of possible values, respectively, but the
  45.     range limits can be presented in either order.  (Reversing the order
  46.     results in an inverting of the returned values, but the distribution
  47.     will still be in the proper range, and no less random.)  The maximum
  48.     number of discrete values that can be generated is MaxInt (32767), thus
  49.     the value abs ( HighValue - LowValue + 1 ) must not exceed MaxInt
  50.     (for example, parameters ( -20000, 20000 ) would not be acceptable).
  51. *)
  52.  
  53. PROCEDURE  DiscreteVariate (
  54.                     (*in*)  LowValue,
  55.                     (*in*)  HighValue: INTEGER ): INTEGER;
  56.  
  57. (*                                                                         [2]
  58.  source: h:\modula\defs\UnifRNG.DEF     v1.0a             revised: 88.07.18 *)
  59.  
  60.  
  61. (*  Return as the function value a general continuous rectangular variate in
  62.     the range specified by the parameters.  The parameters are supposed to be
  63.     the low and high ends of the range of possible values, respectively, but
  64.     the range limits can be presented in either order.  (Reversing the order
  65.     results in an inverting of the returned values, but the distribution will
  66.     be no less random.)  Resulting values are confined to the interval
  67.     [ LowValue, HighValue ) for the case of parameters in normal order, and
  68.     to ( HighValue, LowValue ] for inverted parameters.  This can be used to
  69.     get special cases:  for uniform variates in the interval ( 0, 1 ] invoke
  70.     this procedure as RectangularVariate ( 1.0, 0.0 ).
  71. *)
  72.  
  73. PROCEDURE  RectangularVariate (
  74.                        (*in*)  LowValue,
  75.                        (*in*)  HighValue: REAL ): LONGREAL;
  76.  
  77.  
  78.  
  79. (*  Return as the function value a Pareto variate with strictly positive
  80.     shape parameter specified by the function parameter.  A negative actual
  81.     parameter is taken as its absolute value;  a zero actual parameter is
  82.     taken as 1.
  83. *)
  84.  
  85. PROCEDURE  ParetoVariate (
  86.                   (*in*)  Shape: REAL ): LONGREAL;
  87.  
  88.  
  89.  
  90. (*  Set the initial value to use for generating random variates.
  91. *)
  92.  
  93. PROCEDURE  SetSeedValue (
  94.                  (*in*)  ValueToSet: LONGCARD );
  95.  
  96.  
  97.  
  98. (*  Get the initial value to use for generating random variates.
  99.     This value can be saved to continue a sequence, and later restored using
  100.     the SetSeedValue procedure, above.
  101. *)
  102.  
  103. PROCEDURE  GetSeedValue (
  104.            (*out*)  VAR  CurrentSeed: LONGCARD );
  105.  
  106. END UnifRNG.
  107.