--- a/Random.st Thu Aug 21 16:44:34 1997 +0200
+++ b/Random.st Thu Aug 21 18:10:25 1997 +0200
@@ -26,7 +26,7 @@
Stream subclass:#Random
instanceVariableNames:'seed increment multiplier modulus'
- classVariableNames:''
+ classVariableNames:'RandomGenerator'
poolDictionaries:''
category:'Magnitude-Numbers'
!
@@ -114,6 +114,76 @@
^self basicNew setSeed
! !
+!Random class methodsFor:'random numbers'!
+
+nextBetween:start and:stop
+ "return a random number between start and stop.
+ 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 nextBetween:start and:stop
+
+ "
+ Transcript showCR:(Random nextBetween:1 and:100).
+ Transcript showCR:(Random nextBetween:1 and:100).
+ Transcript showCR:(Random nextBetween:1 and:100).
+ Transcript showCR:(Random nextBetween:1 and:100).
+ "
+
+ "Modified: 21.8.1997 / 18:08:56 / cg"
+ "Created: 21.8.1997 / 18:09:36 / cg"
+!
+
+nextInteger
+ "return an integral random number.
+ 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 nextInteger.
+
+ "
+ Transcript showCR:(Random nextInteger).
+ Transcript showCR:(Random nextInteger).
+ Transcript showCR:(Random nextInteger).
+ Transcript showCR:(Random nextInteger).
+ "
+
+ "Created: 21.8.1997 / 18:08:23 / cg"
+!
+
+nextIntegerBetween:start and:stop
+ "return an integral random number between start and stop.
+ 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 nextIntegerBetween:start and:stop
+
+ "
+ Transcript showCR:(Random nextIntegerBetween:1 and:10).
+ Transcript showCR:(Random nextIntegerBetween:1 and:10).
+ Transcript showCR:(Random nextIntegerBetween:1 and:10).
+ Transcript showCR:(Random nextIntegerBetween:1 and:10).
+ "
+
+ "Created: 21.8.1997 / 18:07:00 / cg"
+ "Modified: 21.8.1997 / 18:08:56 / cg"
+! !
+
!Random class methodsFor:'testing'!
chiSquareTest
@@ -173,7 +243,7 @@
!
nextBetween:start and:stop
- "return a random between start and stop.
+ "return a random number between start and stop.
claus: the original GNU version has a bug in returning values
from the interval [start .. stop+1]"
@@ -191,6 +261,8 @@
Transcript showCR:(r nextBetween:1 and:10).
Transcript showCR:(r nextBetween:1 and:10).
"
+
+ "Modified: 21.8.1997 / 18:10:00 / cg"
!
nextBoolean
@@ -230,7 +302,7 @@
!
nextIntegerBetween:start and:stop
- "return an integral random between start and stop"
+ "return an integral random number between start and stop"
|rnd|
@@ -245,6 +317,8 @@
Transcript showCR:(r nextIntegerBetween:1 and:10).
Transcript showCR:(r nextIntegerBetween:1 and:10).
"
+
+ "Modified: 21.8.1997 / 18:10:08 / cg"
!
nextMatchFor: aNumber
@@ -317,5 +391,5 @@
!Random class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/Random.st,v 1.19 1997-04-16 14:49:19 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/Random.st,v 1.20 1997-08-21 16:10:25 cg Exp $'
! !