Random.st
changeset 680 a7b98fdac3dc
parent 561 f00675b5531f
child 793 037f3ceb4e0a
--- a/Random.st	Mon Aug 17 10:06:01 1998 +0200
+++ b/Random.st	Fri Aug 21 14:47:38 1998 +0200
@@ -250,7 +250,7 @@
     |rnd|
 
     rnd := self next.
-    rnd := rnd * (stop asFloat - start asFloat).
+    rnd := rnd * (stop - start) asFloat.
     rnd := rnd + start asFloat.
     ^ rnd
 
@@ -262,7 +262,7 @@
      Transcript showCR:(r nextBetween:1 and:10).
     "
 
-    "Modified: 21.8.1997 / 18:10:00 / cg"
+    "Modified: / 21.8.1998 / 14:45:27 / cg"
 !
 
 nextBoolean
@@ -278,7 +278,17 @@
      Transcript showCR:r nextBoolean.
     "
 
-    "Modified: 1.4.1997 / 22:52:19 / cg"
+    "
+     |r bag|
+     r := Random new.
+     bag := Bag new.
+     1000000 timesRepeat:[
+         bag add:(r nextBoolean).
+     ].
+     Transcript showCR:bag contents
+    "
+
+    "Modified: / 21.8.1998 / 14:45:55 / cg"
 !
 
 nextInteger
@@ -306,11 +316,12 @@
 
     |rnd|
 
-    rnd := self next.
-    rnd := rnd * (stop asFloat - start asFloat + 1.0).
-    ^ (rnd + start) truncated.
+    rnd := self next.                               
+    rnd := rnd * ((stop - start) asFloat + 1.0).    
+    ^ rnd truncated + start
 
-    "|r|
+    "
+     |r|
      r := Random new.
      Transcript showCR:(r nextIntegerBetween:1 and:10).
      Transcript showCR:(r nextIntegerBetween:1 and:10).
@@ -318,7 +329,17 @@
      Transcript showCR:(r nextIntegerBetween:1 and:10).
     "
 
-    "Modified: 21.8.1997 / 18:10:08 / cg"
+    "
+     |r bag|
+     r := Random new.
+     bag := Bag new.
+     1000000 timesRepeat:[
+         bag add:(r nextIntegerBetween:-1 and:1).
+     ].
+     Transcript showCR:bag contents
+    "
+
+    "Modified: / 21.8.1998 / 14:45:04 / cg"
 !
 
 nextMatchFor: aNumber
@@ -391,5 +412,5 @@
 !Random class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/Random.st,v 1.20 1997-08-21 16:10:25 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Random.st,v 1.21 1998-08-21 12:47:38 cg Exp $'
 ! !