RAND.LST 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. Listing:
  2. 1 (*# check(stack=>off,
  3. 2 index=>off,
  4. 3 range=>off,
  5. 4 overflow=>off,
  6. 5 nil_ptr=>off) *)
  7. 6 IMPLEMENTATION MODULE Rand;
  8. 7 (******************************************************************************)
  9. 8 (* Modify by John McMonagle 4/19/88 *)
  10. 9 (* MODULA-2 Library *)
  11. 10 (* *)
  12. 11 (* LOGITECH SA, CH-1111 Romanel (Switzerland) *)
  13. 12 (* LOGITECH Inc, Fremont, CA 94555 (USA) *)
  14. 13 (* *)
  15. 14 (* Module : Random, random number generator *)
  16. 15 (* *)
  17. 16 (* Release : 3.0 - July 87 *)
  18. 17 (* *)
  19. 18 (* Copyright (C) 1987 Logitech, All rights reserved *)
  20. 19 (* *)
  21. 20 (* Permission is hereby granted to registered users to use or abstract *)
  22. 21 (* the following program in the implementation of customized versions. *)
  23. 22 (* This permission does not include the right to redistribute the *)
  24. 23 (* source code of this program. *)
  25. 24 (* *)
  26. 25 (******************************************************************************)
  27. 26
  28. 27 (*----------------------------------------------------------------------------
  29. 28 Algorithm: Additive congruential method (D.Knuth)
  30. 29 ----------------------------------------------------------------------------*)
  31. 30 (*/NOCHECK:O *)
  32. 31 FROM EnvironUtils IMPORT
  33. 32 GetTime;
  34. 33 FROM NumTypes IMPORT
  35. 34 Real8;
  36. 35
  37. 36 CONST
  38. 37 C = 53;(* was54 *)
  39. 38 R = 65536.0;
  40. 39
  41. 40 VAR
  42. 41 a : ARRAY [0 .. C] OF CARDINAL;
  43. ***** ^ not supported yet
  44. ***** ^ not supported yet
  45. 42 j, k : [0 .. C];
  46. ***** ^ not supported yet
  47. 43
  48. 44
  49. 45 PROCEDURE Next (): CARDINAL;
  50. 46 BEGIN
  51. 47 INC(a [k], a [j]);
  52. ***** ^ undeclared identifier
  53. ***** ^ not supported yet
  54. ***** ^ not supported yet
  55. ***** ^ not supported yet
  56. ***** ^ not supported yet
  57. 48
  58. 49 IF k = 0 THEN
  59. ***** ^ not supported yet
  60. 50 k := C;
  61. ***** ^ not supported yet
  62. 51 ELSE
  63. 52 DEC(k);
  64. ***** ^ undeclared identifier
  65. ***** ^ not supported yet
  66. 53 END;
  67. 54 IF j = 0 THEN
  68. ***** ^ not supported yet
  69. 55 j := C;
  70. ***** ^ not supported yet
  71. 56 ELSE
  72. 57 DEC(j);
  73. ***** ^ undeclared identifier
  74. ***** ^ not supported yet
  75. 58 END;
  76. 59
  77. 60 RETURN a [k];
  78. ***** ^ not supported yet
  79. ***** ^ not supported yet
  80. 61 END Next;
  81. ***** ^ not supported yet
  82. 62
  83. 63 PROCEDURE RandomInit (seed : CARDINAL);
  84. 64 VAR
  85. 65 i, dummy : CARDINAL;
  86. 66 BEGIN
  87. 67 j := 23;(* was 24 *)
  88. ***** ^ not supported yet
  89. 68 k := 0;
  90. ***** ^ not supported yet
  91. 69 FOR i := 0 TO C DO
  92. 70 a [i] := 0;
  93. ***** ^ not supported yet
  94. ***** ^ not supported yet
  95. 71 END;
  96. 72 a [k] := 31415 + seed;
  97. ***** ^ not supported yet
  98. ***** ^ not supported yet
  99. 73 IF a [k] = 0 THEN
  100. ***** ^ not supported yet
  101. ***** ^ not supported yet
  102. 74 a [k] := 31415;
  103. ***** ^ not supported yet
  104. ***** ^ not supported yet
  105. 75 END;
  106. 76 (* added 4/19/88 make sure seed is odd or all will be even *)
  107. 77 IF NOT ODD(a[k])
  108. ***** ^ undeclared identifier
  109. ***** ^ not supported yet
  110. ***** ^ not supported yet
  111. 78 THEN
  112. 79 INC(a[k]);
  113. ***** ^ undeclared identifier
  114. ***** ^ not supported yet
  115. ***** ^ not supported yet
  116. 80 END;
  117. 81 FOR i := 0 TO 1219 DO(* was 1999 reduced as precision is not required *)
  118. 82 dummy := Next ();
  119. ***** ^ not supported yet
  120. ***** ^ not supported yet
  121. 83 END;
  122. 84 END RandomInit;
  123. ***** ^ not supported yet
  124. 85
  125. 86 PROCEDURE RandomCard (bound : CARDINAL): CARDINAL;
  126. 87 BEGIN
  127. 88 IF bound = 0 THEN
  128. 89 RETURN Next ();
  129. ***** ^ not supported yet
  130. ***** ^ not supported yet
  131. 90 ELSE
  132. 91 RETURN Next() MOD bound;
  133. ***** ^ not supported yet
  134. ***** ^ not supported yet
  135. 92 (* RETURN TRUNC (FLOAT (bound) * FLOAT (Next ()) / R); *)
  136. 93 END;
  137. 94 END RandomCard;
  138. ***** ^ not supported yet
  139. 95
  140. 96 PROCEDURE RandomInt (bound : INTEGER): INTEGER;
  141. 97 BEGIN
  142. 98 RETURN INTEGER (RandomCard (CARDINAL (ABS (bound))));
  143. ***** ^ not supported yet
  144. ***** ^ undeclared identifier
  145. ***** ^ not supported yet
  146. 99 END RandomInt;
  147. ***** ^ not supported yet
  148. 100 (*
  149. 101 PROCEDURE RandomReal () : Real8;
  150. 102 BEGIN
  151. 103 RETURN VAL(Real8,RandomCard (10000)) * 1.0E-16 +
  152. 104 VAL(Real8,RandomCard (10000)) * 1.0E-12 +
  153. 105 VAL(Real8,RandomCard (10000)) * 1.0E-08 +
  154. 106 VAL(Real8,RandomCard (10000)) * 1.0E-04;
  155. 107 END RandomReal;
  156. 108
  157. 109 *)
  158. 110 PROCEDURE Randomize;
  159. 111 VAR
  160. 112 minute,second,hundredths,
  161. 113 i, j : CARDINAL;
  162. 114 dummy: CARDINAL;
  163. 115 str: ARRAY[0..40] OF CHAR;
  164. ***** ^ not supported yet
  165. ***** ^ not supported yet
  166. 116 BEGIN
  167. 117 GetTime(dummy,minute,second,hundredths,str);
  168. ***** ^ not supported yet
  169. ***** ^ not supported yet
  170. 118 RandomInit (hundredths*second);
  171. ***** ^ not supported yet
  172. ***** ^ not supported yet
  173. 119 j := minute;
  174. 120 FOR i := 0 TO j DO
  175. 121 dummy := Next ();
  176. ***** ^ not supported yet
  177. ***** ^ not supported yet
  178. 122 END;
  179. 123 END Randomize;
  180. ***** ^ not supported yet
  181. 124
  182. 125
  183. 126 BEGIN
  184. 127 Randomize;
  185. ***** ^ not supported yet
  186. 128 (* FOR j:=0 TO C DO
  187. 129 a[j]:=0;
  188. 130 END;
  189. 131 j:=0;
  190. 132 k:=0; *)
  191. 133 END Rand.
  192. ***** ^ not supported yet
  193. 58 errors