--- a/Random.st Fri Jul 26 15:30:30 2019 +0200
+++ b/Random.st Sun Jul 28 12:33:34 2019 +0200
@@ -156,6 +156,37 @@
"
!
+next:n
+ "return the next n random numbers in the range 0..1
+ 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."
+
+ ^ self sharedGenerator next:n.
+
+ "
+ Transcript showCR:(Random next:10).
+ "
+!
+
+next:n between:start and:stop
+ "return n random numbers 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."
+
+ ^ self sharedGenerator next:n between:start and:stop
+
+ "
+ Transcript showCR:(Random next:10 between:1 and:100).
+ "
+
+ "Modified: 21.8.1997 / 18:08:56 / cg"
+ "Created: 21.8.1997 / 18:09:36 / cg"
+!
+
nextBetween:start and:stop
"return a random number between start and stop.
This method behaves like the corresponding instance method,
@@ -447,6 +478,25 @@
"
!
+next:count between:min and:max
+ "return the next count random numbers in min..max"
+
+ |answerStream
+ cnt "{ Class: SmallInteger }" |
+
+ cnt := count.
+ answerStream := self contentsSpecies writeStream:cnt.
+ 1 to:cnt do:[:index | |next|
+ next := self nextBetween:min and:max.
+ answerStream nextPut:next.
+ ].
+ ^ answerStream contents
+
+ "
+ (RandomGenerator new) next:10 between:0 and:100
+ "
+!
+
next:count integerBetween:min and:max
"return the next count random integers in min..max"