checkin from browser
authorClaus Gittinger <cg@exept.de>
Fri, 10 Dec 1999 03:02:43 +0100
changeset 851 e1c3af12daca
parent 850 cca26a229b5e
child 852 90d52d38657e
checkin from browser
Random.st
--- a/Random.st	Sat Dec 04 16:06:04 1999 +0100
+++ b/Random.st	Fri Dec 10 03:02:43 1999 +0100
@@ -151,6 +151,28 @@
     "Created: 21.8.1997 / 18:09:36 / cg"
 !
 
+nextBoolean
+    "return a boolean random.
+     This method behaves like the corresponding instance method,
+     but allows generation of random numbers without
+     a need for an instance of Random to be kept around.
+     This uses a common, shared generator."
+
+    RandomGenerator isNil ifTrue:[
+        RandomGenerator := self new.
+    ].
+    ^ RandomGenerator nextBoolean.
+
+    "
+     Transcript showCR:(Random nextBoolean).
+     Transcript showCR:(Random nextBoolean).
+     Transcript showCR:(Random nextBoolean).
+     Transcript showCR:(Random nextBoolean).
+    "
+
+    "Created: 21.8.1997 / 18:08:23 / cg"
+!
+
 nextInteger
     "return an integral random number.
      This method behaves like the corresponding instance method,
@@ -314,7 +336,7 @@
 nextBoolean
     "return true or false by random"
 
-    ^ self nextInteger < (modulus / 2)
+    ^ self next < 0.5
 
     "|r|
      r := Random new.
@@ -501,5 +523,5 @@
 !Random class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/Random.st,v 1.24 1999-11-12 16:51:04 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Random.st,v 1.25 1999-12-10 02:02:43 cg Exp $'
 ! !