Random.st
changeset 842 718e00244ba4
parent 840 5f6559515588
child 851 e1c3af12daca
--- a/Random.st	Tue Nov 09 14:05:48 1999 +0100
+++ b/Random.st	Fri Nov 12 17:51:04 1999 +0100
@@ -64,6 +64,11 @@
 documentation
 "
     random numbers - thanks to Steves GNU Smalltalk
+    This implements a linear congruential maximum period random number generator
+    which passes the spectral test for randomness for dimensions 2 3 4 5 6.
+
+    DO NOT USE IT FOR CRYPTOGRAPHY, because linear congruential generators
+    are predictable and can be broken easily!!
 
     Notice: although being included here,
             this file is NOT covered by the ST/X license, but by
@@ -75,8 +80,6 @@
             software, which can be copied and given away without any 
             restriction from my (CG) side.
 
-    claus: the algorithm may need a rewrite for better numbers
-
     [author:]
         Steve Byrne
         Claus Gittinger
@@ -112,6 +115,15 @@
     "return a new random generator"
 
     ^self basicNew setSeed
+!
+
+random
+    "return a new random generator.
+     Defined here for compatibility with StreamCipher"
+
+    ^ self new
+
+    "Created: / 12.11.1999 / 17:52:08 / stefan"
 ! !
 
 !Random class methodsFor:'random numbers'!
@@ -441,19 +453,21 @@
 !Random methodsFor:'private'!
 
 setSeed
-    "set the initial seed value based on the current time"
+    "set the initial seed value based on the current time.
+     These numbers implement a maximum period generator which passes
+     the spectral test for randomness for dimensions 2 3 4 5 6 and
+     the product does not overflow  2 raisedTo:29.
+
+     These numbers are carefully choosen, so don't change them, 
+     unless you know what you are doing!!"
 
     seed := Time millisecondClockValue bitAnd:16rFFFF.
-    multiplier := 2311.
-    increment := 25367.
-    modulus := 120050.
+    multiplier := 1597.
+    increment := 51749.
+    modulus := 244944.
 
-"/    seed := Time secondClock bitAnd: 16r3FFFFFFF
-"/    multiplier := 31415821.
-"/    modulus := 16r3FFFFFFF.
-"/    increment := 1.
-
-    "Modified: 1.4.1997 / 22:44:13 / cg"
+    "Modified: / 1.4.1997 / 22:44:13 / cg"
+    "Modified: / 12.11.1999 / 17:50:52 / stefan"
 !
 
 step
@@ -487,5 +501,5 @@
 !Random class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/Random.st,v 1.23 1999-11-08 20:46:49 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Random.st,v 1.24 1999-11-12 16:51:04 stefan Exp $'
 ! !