author | Claus Gittinger <cg@exept.de> |
Fri, 02 Mar 2018 18:54:07 +0100 | |
changeset 4614 | 86242cfe8f40 |
parent 4613 | 7229c9649f3e |
child 4627 | 62d147dd6abc |
permissions | -rw-r--r-- |
4599 | 1 |
"{ Encoding: utf8 }" |
2 |
||
65 | 3 |
" |
4600 | 4 |
COPYRIGHT (c) 1989 by Claus Gittinger |
5 |
All Rights Reserved |
|
0 | 6 |
|
4600 | 7 |
This software is furnished under a license and may be used |
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
0 | 13 |
" |
928 | 14 |
"{ Package: 'stx:libbasic2' }" |
15 |
||
3675 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
0 | 18 |
Stream subclass:#Random |
4600 | 19 |
instanceVariableNames:'seed' |
20 |
classVariableNames:'RandomSalt SharedGenerator' |
|
232 | 21 |
poolDictionaries:'' |
4590 | 22 |
category:'Magnitude-Numbers-Random' |
0 | 23 |
! |
24 |
||
65 | 25 |
!Random class methodsFor:'documentation'! |
0 | 26 |
|
31 | 27 |
copyright |
28 |
" |
|
4600 | 29 |
COPYRIGHT (c) 1989 by Claus Gittinger |
30 |
All Rights Reserved |
|
31 | 31 |
|
4600 | 32 |
This software is furnished under a license and may be used |
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
31 | 38 |
" |
39 |
! |
|
40 |
||
41 |
documentation |
|
42 |
" |
|
4600 | 43 |
A facade to the actual RandomGenerator. |
44 |
In previous versions, Random was a very bad fallback random generator, |
|
45 |
with an included warning, to not use it. |
|
4481 | 46 |
|
4600 | 47 |
Now this old generator was renamed to RandomGNUSmalltalk, |
48 |
and the default generator used is the one provided by the much |
|
49 |
better RandomGenerator class. |
|
4481 | 50 |
|
4600 | 51 |
Random new next:10 |
75 | 52 |
|
258 | 53 |
[author:] |
54 |
Claus Gittinger |
|
947 | 55 |
|
56 |
[see also:] |
|
3394 | 57 |
http://www0.cs.ucl.ac.uk/staff/d.jones/GoodPracticeRNG.pdf |
998 | 58 |
RandomTT800 - a new random generator |
59 |
RandomParkMiller - another new random generator |
|
271 | 60 |
" |
61 |
! |
|
62 |
||
63 |
examples |
|
64 |
" |
|
65 |
[exBegin] |
|
66 |
|rnd| |
|
258 | 67 |
|
271 | 68 |
rnd := Random new. |
69 |
10 timesRepeat:[ |
|
350 | 70 |
Transcript showCR:(rnd next) |
271 | 71 |
] |
72 |
[exEnd] |
|
73 |
||
74 |
rolling a dice: |
|
75 |
[exBegin] |
|
76 |
|rnd| |
|
77 |
||
78 |
rnd := Random new. |
|
79 |
10 timesRepeat:[ |
|
350 | 80 |
Transcript showCR:(rnd nextIntegerBetween:1 and:6) |
271 | 81 |
] |
82 |
[exEnd] |
|
31 | 83 |
" |
84 |
! ! |
|
0 | 85 |
|
65 | 86 |
!Random class methodsFor:'instance creation'! |
0 | 87 |
|
88 |
new |
|
4600 | 89 |
"return a new random generator. |
90 |
Here, this instance creation message is forwarded to the standardGenerator" |
|
17 | 91 |
|
4612 | 92 |
self == Random ifFalse:[^ super new]. |
4600 | 93 |
^ self standard |
94 |
||
95 |
" |
|
96 |
Random new |
|
97 |
" |
|
842 | 98 |
! |
99 |
||
100 |
random |
|
101 |
"return a new random generator. |
|
102 |
Defined here for compatibility with StreamCipher" |
|
103 |
||
4600 | 104 |
^ self standard |
842 | 105 |
|
106 |
"Created: / 12.11.1999 / 17:52:08 / stefan" |
|
1128 | 107 |
! |
108 |
||
1878 | 109 |
seed:seedValue |
4600 | 110 |
"return a new random generator with initial seed. |
111 |
Here, this instance creation message is forwarded to the standardGenerator" |
|
1878 | 112 |
|
4613 | 113 |
self == Random ifFalse:[^ self basicNew seed:seedValue]. |
4600 | 114 |
^ self standardGeneratorClass basicNew setSeed:seedValue |
1878 | 115 |
|
116 |
"Created: / 26-05-2007 / 21:27:18 / cg" |
|
117 |
! |
|
118 |
||
1128 | 119 |
sharedGenerator |
120 |
"return a shared random generator." |
|
121 |
||
3134 | 122 |
SharedGenerator isNil ifTrue:[ |
4600 | 123 |
SharedGenerator := self standard. |
1128 | 124 |
]. |
3134 | 125 |
^ SharedGenerator |
2291 | 126 |
! |
127 |
||
128 |
standard |
|
129 |
"return the 'standard' generator" |
|
130 |
||
4600 | 131 |
^ self standardGeneratorClass new |
132 |
! |
|
133 |
||
134 |
standardGeneratorClass |
|
135 |
"return the class used for the 'standard' generator" |
|
136 |
||
137 |
^ RandomGenerator |
|
0 | 138 |
! ! |
139 |
||
561
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
140 |
!Random class methodsFor:'random numbers'! |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
141 |
|
3171 | 142 |
next |
143 |
"return the next random number in the range 0..1 |
|
144 |
This method behaves like the corresponding instance method, |
|
145 |
but allows generation of random numbers without |
|
146 |
a need for an instance of Random to be kept around. |
|
147 |
This uses a common, shared generator." |
|
148 |
||
149 |
^ self sharedGenerator next. |
|
150 |
||
151 |
" |
|
152 |
Transcript showCR:(Random next). |
|
153 |
Transcript showCR:(Random next). |
|
154 |
Transcript showCR:(Random next). |
|
155 |
Transcript showCR:(Random next). |
|
156 |
" |
|
157 |
! |
|
158 |
||
561
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
159 |
nextBetween:start and:stop |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
160 |
"return a random number between start and stop. |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
161 |
This method behaves like the corresponding instance method, |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
162 |
but allows generation of random numbers without |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
163 |
a need for an instance of Random to be kept around. |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
164 |
This uses a common, shared generator." |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
165 |
|
1128 | 166 |
^ self sharedGenerator nextBetween:start and:stop |
561
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
167 |
|
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
168 |
" |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
169 |
Transcript showCR:(Random nextBetween:1 and:100). |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
170 |
Transcript showCR:(Random nextBetween:1 and:100). |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
171 |
Transcript showCR:(Random nextBetween:1 and:100). |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
172 |
Transcript showCR:(Random nextBetween:1 and:100). |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
173 |
" |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
174 |
|
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
175 |
"Modified: 21.8.1997 / 18:08:56 / cg" |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
176 |
"Created: 21.8.1997 / 18:09:36 / cg" |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
177 |
! |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
178 |
|
851 | 179 |
nextBoolean |
180 |
"return a boolean random. |
|
181 |
This method behaves like the corresponding instance method, |
|
182 |
but allows generation of random numbers without |
|
183 |
a need for an instance of Random to be kept around. |
|
184 |
This uses a common, shared generator." |
|
185 |
||
1128 | 186 |
^ self sharedGenerator nextBoolean. |
851 | 187 |
|
188 |
" |
|
189 |
Transcript showCR:(Random nextBoolean). |
|
190 |
Transcript showCR:(Random nextBoolean). |
|
191 |
Transcript showCR:(Random nextBoolean). |
|
192 |
Transcript showCR:(Random nextBoolean). |
|
193 |
" |
|
194 |
||
195 |
"Created: 21.8.1997 / 18:08:23 / cg" |
|
196 |
! |
|
197 |
||
561
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
198 |
nextInteger |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
199 |
"return an integral random number. |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
200 |
This method behaves like the corresponding instance method, |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
201 |
but allows generation of random numbers without |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
202 |
a need for an instance of Random to be kept around. |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
203 |
This uses a common, shared generator." |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
204 |
|
1128 | 205 |
^ self sharedGenerator nextInteger. |
561
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
206 |
|
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
207 |
" |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
208 |
Transcript showCR:(Random nextInteger). |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
209 |
Transcript showCR:(Random nextInteger). |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
210 |
Transcript showCR:(Random nextInteger). |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
211 |
Transcript showCR:(Random nextInteger). |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
212 |
" |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
213 |
|
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
214 |
"Created: 21.8.1997 / 18:08:23 / cg" |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
215 |
! |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
216 |
|
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
217 |
nextIntegerBetween:start and:stop |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
218 |
"return an integral random number between start and stop. |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
219 |
This method behaves like the corresponding instance method, |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
220 |
but allows generation of random numbers without |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
221 |
a need for an instance of Random to be kept around. |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
222 |
This uses a common, shared generator." |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
223 |
|
1128 | 224 |
^ self sharedGenerator nextIntegerBetween:start and:stop |
561
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
225 |
|
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
226 |
" |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
227 |
Transcript showCR:(Random nextIntegerBetween:1 and:10). |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
228 |
Transcript showCR:(Random nextIntegerBetween:1 and:10). |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
229 |
Transcript showCR:(Random nextIntegerBetween:1 and:10). |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
230 |
Transcript showCR:(Random nextIntegerBetween:1 and:10). |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
231 |
" |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
232 |
|
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
233 |
"Created: 21.8.1997 / 18:07:00 / cg" |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
234 |
"Modified: 21.8.1997 / 18:08:56 / cg" |
3750 | 235 |
! |
236 |
||
237 |
nextLettersOrDigits:count |
|
238 |
"get the next count printable letters or digits [0-9A-Za-z]." |
|
239 |
||
240 |
^ self sharedGenerator nextLettersOrDigits:count |
|
241 |
||
242 |
" |
|
243 |
Transcript showCR:(Random nextLettersOrDigits:10). |
|
244 |
Transcript showCR:(Random nextLettersOrDigits:10). |
|
245 |
Transcript showCR:(Random nextLettersOrDigits:10). |
|
246 |
Transcript showCR:(Random nextLettersOrDigits:10). |
|
247 |
" |
|
248 |
||
249 |
"Created: 21.8.1997 / 18:07:00 / cg" |
|
250 |
"Modified: 21.8.1997 / 18:08:56 / cg" |
|
561
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
251 |
! ! |
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
252 |
|
3383 | 253 |
!Random class methodsFor:'seeding'! |
254 |
||
255 |
randomSeed |
|
256 |
"return a number useful for seeding. |
|
257 |
This takes the current processor's time, plus the processor's process id, |
|
258 |
plus some value depending on the memory allocation state, |
|
3403 | 259 |
plus a random salt, and shuffles those bits around. |
260 |
The entropy returned should be reasonable enough for a good seed of a good rnd |
|
261 |
generator. However, keep in mind, that it only has a limited number of entropy bits |
|
262 |
(in the order of 32). |
|
3414 | 263 |
But it should be much better than what is commonly used in older |
3403 | 264 |
programs (current time) or even a constant." |
3383 | 265 |
|
3414 | 266 |
|hash| |
267 |
||
3383 | 268 |
RandomSalt isNil ifTrue:[ |
269 |
RandomSalt := 1. |
|
270 |
] ifFalse:[ |
|
271 |
RandomSalt := RandomSalt + 1. |
|
272 |
]. |
|
3431 | 273 |
|
274 |
hash := MD5Stream new. |
|
275 |
hash |
|
276 |
nextPut:RandomSalt; |
|
277 |
nextPut:Time microsecondClockValue; |
|
278 |
nextPut:OperatingSystem getProcessId; |
|
279 |
nextPut:(ObjectMemory addressOf:Object new); |
|
280 |
nextPut:ObjectMemory oldSpaceUsed; |
|
4198 | 281 |
nextPut:ObjectMemory newSpaceUsed; |
282 |
nextPut:OperatingSystem getCPUCycleCount. |
|
3403 | 283 |
|
3414 | 284 |
"/ any other cheap sources of entropy? |
3403 | 285 |
|
4198 | 286 |
"/ I think there is no problem in that MD5 is not a secure hash algo here |
287 |
"/ - the idea is to shuffle the bits around a bit |
|
3403 | 288 |
"/ (because the numbers above usually have many high bits in common) |
289 |
"/ and then condense the bits into a smaller number. |
|
290 |
"/ Any comment from a crypto guy here - I am willing to change this to some other hash, if that makes a problem |
|
291 |
||
3414 | 292 |
"/ Seeding rnd generators should take some bits from the returned number (i.e. their max. seed size) |
293 |
^ LargeInteger digitBytes:hash hashValue. |
|
3383 | 294 |
|
295 |
" |
|
3403 | 296 |
10 timesRepeat:[Transcript showCR:self randomSeed]. |
3414 | 297 |
10 timesRepeat:[Transcript showCR:(self randomSeed bitAnd:16rFFFF)]. |
3403 | 298 |
self randomSeed bitAnd:16rFFFFFFFF |
3383 | 299 |
" |
300 |
! ! |
|
301 |
||
518 | 302 |
!Random class methodsFor:'testing'! |
303 |
||
793 | 304 |
bucketTest: randy |
305 |
"A quick-and-dirty bucket test. Prints nbuckets values on the Transcript. |
|
306 |
Each should be 'near' the value of ntries. Any run with any value 'far' from ntries |
|
307 |
indicates something is very wrong. Each run generates different values. |
|
308 |
For a slightly better test, try values of nbuckets of 200-1000 or more; |
|
309 |
go get coffee. |
|
310 |
This is a poor test; see Knuth. |
|
311 |
Some 'OK' runs: |
|
312 |
1000 1023 998 969 997 1018 1030 1019 1054 985 1003 |
|
313 |
1011 987 982 980 982 974 968 1044 976 |
|
314 |
1029 1011 1025 1016 997 1019 991 954 968 999 991 |
|
315 |
978 1035 995 988 1038 1009 988 993 976 |
|
316 |
" |
|
317 |
||
318 |
| nbuckets buckets ntrys slot | |
|
319 |
||
320 |
nbuckets := 20. |
|
3192 | 321 |
buckets := Array new: nbuckets withAll:0. |
793 | 322 |
ntrys := 1000. |
323 |
ntrys*nbuckets timesRepeat: [ |
|
324 |
slot := (randy next * nbuckets) floor + 1. |
|
325 |
buckets at: slot put: (buckets at: slot) + 1 ]. |
|
326 |
Transcript cr. |
|
327 |
1 to: nbuckets do: [ :nb | |
|
328 |
Transcript show: (buckets at: nb) printString, ' ' ] |
|
329 |
||
330 |
||
331 |
"Execute this: |
|
3192 | 332 |
self bucketTest: self new |
333 |
self bucketTest: RandomGenerator new |
|
793 | 334 |
" |
335 |
! |
|
336 |
||
518 | 337 |
chiSquareTest |
338 |
" Chi-Squared Test - from R.Sedgewick's 1st ed. of 'Algorithms', |
|
339 |
o N = number of samples |
|
340 |
o r = range of random numners is [0,r) -- condition: N >= 10r. |
|
341 |
o Random number generator 'passes' if chisquare value is very close to r |
|
342 |
o Repeat test several times, since it may be *wrong* 1 out of 10 trials." |
|
343 |
||
3192 | 344 |
| aGenerator frequencies n range t | |
345 |
||
346 |
aGenerator := self new. "Seeded differently each time (if seeded at all)" |
|
347 |
range := 100. |
|
348 |
n := 10000. |
|
349 |
frequencies := Array new:range withAll:0. |
|
518 | 350 |
|
3192 | 351 |
1 to: n do: [:i | |
352 |
t := ((aGenerator next) * range) truncated + 1. |
|
353 |
frequencies at:t put: ((frequencies at:t) + 1). |
|
518 | 354 |
]. |
3192 | 355 |
t := frequencies inject:0 into: [:nextValue :eachFreq | |
356 |
nextValue + eachFreq squared |
|
357 |
]. |
|
358 |
^ ((range * t / n) - n) asFloat. |
|
518 | 359 |
|
360 |
" |
|
3192 | 361 |
self chiSquareTest |
362 |
RandomGenerator chiSquareTest |
|
363 |
" |
|
364 |
||
365 |
" |
|
366 |
|fail| |
|
367 |
fail := 0. |
|
368 |
10 timesRepeat:[ |
|
369 |
|testResult| |
|
370 |
testResult := RandomGenerator chiSquareTest. |
|
371 |
(100 - testResult) abs > 20 ifTrue:[Transcript showCR:testResult. fail := fail + 1]. |
|
372 |
]. |
|
373 |
fail > 1 ifTrue:[self error:'test failed']. |
|
518 | 374 |
" |
375 |
||
376 |
" |
|
377 |
Sedgewick claims each chisquare number should be 100 +- 20. |
|
378 |
The closer to 100, the better. |
|
379 |
" |
|
380 |
! ! |
|
381 |
||
1201 | 382 |
!Random methodsFor:'Compatibility-Squeak'! |
928 | 383 |
|
2309
9f2c39c721db
added: #nextInt: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
384 |
nextInt:upperBound |
9f2c39c721db
added: #nextInt: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
385 |
"Answer a random integer in the interval [1, anInteger]." |
9f2c39c721db
added: #nextInt: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
386 |
|
3188 | 387 |
(upperBound < 1) ifTrue:[self error:'invalid upper bound']. |
388 |
||
2309
9f2c39c721db
added: #nextInt: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
389 |
^ self nextIntegerBetween:1 and:upperBound |
9f2c39c721db
added: #nextInt: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
390 |
|
9f2c39c721db
added: #nextInt: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
391 |
" |
9f2c39c721db
added: #nextInt: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
392 |
Random new nextInt:10 |
9f2c39c721db
added: #nextInt: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
393 |
" |
9f2c39c721db
added: #nextInt: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
394 |
! |
9f2c39c721db
added: #nextInt: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
395 |
|
928 | 396 |
nextIntFrom:lowerBound to:upperBound |
397 |
"return a random integer in the given range" |
|
398 |
||
399 |
^ self nextIntegerBetween:lowerBound and:upperBound |
|
400 |
||
401 |
" |
|
402 |
Random new nextIntFrom:5 to:10 |
|
403 |
" |
|
3060
5267b3c2754c
added: #seed: for compatibility with Squeak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3026
diff
changeset
|
404 |
! |
5267b3c2754c
added: #seed: for compatibility with Squeak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3026
diff
changeset
|
405 |
|
5267b3c2754c
added: #seed: for compatibility with Squeak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3026
diff
changeset
|
406 |
seed: anInteger |
5267b3c2754c
added: #seed: for compatibility with Squeak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3026
diff
changeset
|
407 |
self setSeed: anInteger. |
5267b3c2754c
added: #seed: for compatibility with Squeak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3026
diff
changeset
|
408 |
|
5267b3c2754c
added: #seed: for compatibility with Squeak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3026
diff
changeset
|
409 |
"Created: / 20-07-2013 / 01:52:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
928 | 410 |
! ! |
411 |
||
65 | 412 |
!Random methodsFor:'accessing-reading'! |
0 | 413 |
|
142 | 414 |
next |
3675 | 415 |
"return the next random number in the range ]0..1[" |
17 | 416 |
|
4600 | 417 |
self subclassResponsibility. |
17 | 418 |
|
3134 | 419 |
" |
420 |
|r| |
|
17 | 421 |
r := Random new. |
350 | 422 |
Transcript showCR:r next. |
423 |
Transcript showCR:r next. |
|
424 |
Transcript showCR:r next. |
|
425 |
Transcript showCR:r next. |
|
17 | 426 |
" |
517
4e47b198c9bc
allow multiplier, increment & modulus to be changed.
Claus Gittinger <cg@exept.de>
parents:
350
diff
changeset
|
427 |
|
4e47b198c9bc
allow multiplier, increment & modulus to be changed.
Claus Gittinger <cg@exept.de>
parents:
350
diff
changeset
|
428 |
"Modified: 1.4.1997 / 22:44:46 / cg" |
0 | 429 |
! |
430 |
||
65 | 431 |
nextBetween:start and:stop |
3675 | 432 |
"return a random number in the range ]start..stop[. |
65 | 433 |
claus: the original GNU version has a bug in returning values |
434 |
from the interval [start .. stop+1]" |
|
435 |
||
436 |
|rnd| |
|
437 |
||
4614 | 438 |
rnd := self nextInteger. |
680
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
439 |
rnd := rnd * (stop - start) asFloat. |
65 | 440 |
rnd := rnd + start asFloat. |
441 |
^ rnd |
|
442 |
||
4614 | 443 |
" |
444 |
|r| |
|
65 | 445 |
r := Random new. |
350 | 446 |
Transcript showCR:(r nextBetween:1 and:10). |
447 |
Transcript showCR:(r nextBetween:1 and:10). |
|
448 |
Transcript showCR:(r nextBetween:1 and:10). |
|
449 |
Transcript showCR:(r nextBetween:1 and:10). |
|
65 | 450 |
" |
561
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
451 |
|
680
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
452 |
"Modified: / 21.8.1998 / 14:45:27 / cg" |
65 | 453 |
! |
454 |
||
0 | 455 |
nextBoolean |
17 | 456 |
"return true or false by random" |
457 |
||
4614 | 458 |
^ self nextInteger bitAnd:16r10. |
17 | 459 |
|
3134 | 460 |
" |
461 |
|r| |
|
17 | 462 |
r := Random new. |
350 | 463 |
Transcript showCR:r nextBoolean. |
464 |
Transcript showCR:r nextBoolean. |
|
465 |
Transcript showCR:r nextBoolean. |
|
466 |
Transcript showCR:r nextBoolean. |
|
17 | 467 |
" |
517
4e47b198c9bc
allow multiplier, increment & modulus to be changed.
Claus Gittinger <cg@exept.de>
parents:
350
diff
changeset
|
468 |
|
680
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
469 |
" |
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
470 |
|r bag| |
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
471 |
r := Random new. |
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
472 |
bag := Bag new. |
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
473 |
1000000 timesRepeat:[ |
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
474 |
bag add:(r nextBoolean). |
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
475 |
]. |
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
476 |
Transcript showCR:bag contents |
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
477 |
" |
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
478 |
|
2045 | 479 |
"Modified: / 22-10-2008 / 15:17:57 / cg" |
0 | 480 |
! |
481 |
||
840 | 482 |
nextByte |
483 |
"return the next integral random number byte in the range 0 .. 16rFF" |
|
484 |
||
4614 | 485 |
^ self nextInteger bitAnd:16rFF |
840 | 486 |
|
487 |
" |
|
488 |
|r| |
|
3134 | 489 |
r := self new. |
840 | 490 |
Transcript showCR:r nextByte. |
491 |
Transcript showCR:r nextByte. |
|
492 |
Transcript showCR:r nextByte. |
|
493 |
Transcript showCR:r nextByte. |
|
494 |
" |
|
495 |
||
496 |
"Modified: 1.4.1997 / 22:42:53 / cg" |
|
497 |
! |
|
498 |
||
499 |
nextBytes:count |
|
978 | 500 |
"return count random bytes (0..16rFF each)" |
840 | 501 |
|
4600 | 502 |
^ (1 to:count) collect:[:i | self nextByte] as:ByteArray |
840 | 503 |
|
504 |
" |
|
4600 | 505 |
Transcript showCR:(RandomGenerator new nextBytes:20). |
840 | 506 |
" |
507 |
||
508 |
"Modified: 1.4.1997 / 22:42:53 / cg" |
|
509 |
! |
|
510 |
||
4599 | 511 |
nextBytesNonZero:count |
512 |
"return count random bytes, none of which is zero (i.e. 1..16rFF each)" |
|
513 |
||
514 |
|res cnt "{Class: SmallInteger}"| |
|
515 |
||
516 |
cnt := count. |
|
517 |
res := ByteArray uninitializedNew:cnt. |
|
518 |
||
519 |
1 to:cnt do:[:i| |
|
520 |
|nextNonZero| |
|
521 |
||
522 |
[ |
|
4611 | 523 |
(nextNonZero := self nextByte) == 0 |
4599 | 524 |
] whileTrue. |
525 |
res at:i put:nextNonZero. |
|
526 |
]. |
|
527 |
||
528 |
^ res |
|
529 |
||
530 |
" |
|
531 |
Transcript showCR:(Random new nextBytesNonZero:20). |
|
532 |
" |
|
533 |
||
534 |
"Modified: 1.4.1997 / 22:42:53 / cg" |
|
535 |
! |
|
536 |
||
1642 | 537 |
nextCharacters:count |
538 |
"get the next cnt printable characters. |
|
3750 | 539 |
We answer printable characters in the ascii range (codepoints 32 - 126)" |
1642 | 540 |
|
4614 | 541 |
^ (1 to:count) collect:[:i | Character value:(self nextInteger \\ 94 + 32) ] as:String |
1642 | 542 |
|
543 |
" |
|
4600 | 544 |
RandomGenerator new nextCharacters:8 |
1642 | 545 |
" |
546 |
! |
|
547 |
||
142 | 548 |
nextInteger |
549 |
"return the next integral random number, |
|
4600 | 550 |
in the range 0 .. self maxInteger" |
3134 | 551 |
|
4600 | 552 |
self subclassResponsibility |
142 | 553 |
|
840 | 554 |
" |
555 |
|r| |
|
142 | 556 |
r := Random new. |
350 | 557 |
Transcript showCR:r nextInteger. |
558 |
Transcript showCR:r nextInteger. |
|
559 |
Transcript showCR:r nextInteger. |
|
560 |
Transcript showCR:r nextInteger. |
|
142 | 561 |
" |
517
4e47b198c9bc
allow multiplier, increment & modulus to be changed.
Claus Gittinger <cg@exept.de>
parents:
350
diff
changeset
|
562 |
|
4e47b198c9bc
allow multiplier, increment & modulus to be changed.
Claus Gittinger <cg@exept.de>
parents:
350
diff
changeset
|
563 |
"Modified: 1.4.1997 / 22:42:53 / cg" |
142 | 564 |
! |
565 |
||
17 | 566 |
nextIntegerBetween:start and:stop |
4600 | 567 |
"return an integral random number in [start..stop] (inclusive)" |
17 | 568 |
|
3026 | 569 |
|rnd range bytesNeeded| |
17 | 570 |
|
3026 | 571 |
range := stop - start + 1. |
4600 | 572 |
"Fetch at least 2 bytes, otherwise we get some unbalanced distributions for small ranges" |
573 |
bytesNeeded := (range highBit + 15) // 8. |
|
574 |
bytesNeeded < 4 ifTrue:[ |
|
575 |
rnd := (((self nextByte bitShift:8) + self nextByte) bitShift:8) + self nextByte. |
|
576 |
rnd := rnd \\ range. |
|
3134 | 577 |
] ifFalse:[ |
4600 | 578 |
rnd := (LargeInteger digitBytes:(self nextBytes:bytesNeeded)) compressed. |
579 |
rnd := rnd \\ range. |
|
3134 | 580 |
]. |
4600 | 581 |
^ rnd + start |
582 |
||
583 |
"shows pair-combination counts |
|
584 |
||
585 |
|r v prev this counts| |
|
586 |
||
587 |
v := TextView new . |
|
588 |
v extent:500@250. |
|
589 |
v list:#('xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx' |
|
590 |
'xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx' |
|
591 |
'xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx' |
|
592 |
'xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx' |
|
593 |
'xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx' |
|
594 |
'xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx' |
|
595 |
'xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx' |
|
596 |
'xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx' |
|
597 |
'xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx' |
|
598 |
'xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx'). |
|
599 |
v openAndWait. |
|
600 |
counts := (1 to:10) collect:[:row | Array new:10 withAll:0]. |
|
601 |
||
602 |
r := self new. |
|
603 |
prev := r nextIntegerBetween:1 and:10. |
|
604 |
10000 timesRepeat:[ |
|
605 |
100 timesRepeat:[ |
|
606 |
this := r nextIntegerBetween:1 and:10. |
|
607 |
(counts at:this) at:prev put:((counts at:this) at:prev)+1. |
|
608 |
]. |
|
609 |
v list:(counts collect:[:row | |
|
610 |
'%4d %4d %4d %4d %4d %4d %4d %4d %4d %4d'printf:row ]). |
|
611 |
prev := this. |
|
612 |
]. |
|
613 |
" |
|
17 | 614 |
|
680
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
615 |
" |
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
616 |
|r| |
3026 | 617 |
r := self new. |
350 | 618 |
Transcript showCR:(r nextIntegerBetween:1 and:10). |
619 |
Transcript showCR:(r nextIntegerBetween:1 and:10). |
|
620 |
Transcript showCR:(r nextIntegerBetween:1 and:10). |
|
621 |
Transcript showCR:(r nextIntegerBetween:1 and:10). |
|
17 | 622 |
" |
561
f00675b5531f
added class protocol for random numbers
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
623 |
|
680
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
624 |
" |
3134 | 625 |
|r| |
626 |
r := self new. |
|
627 |
Transcript showCR:(r nextIntegerBetween:1 and:1000000). |
|
628 |
Transcript showCR:(r nextIntegerBetween:1 and:1000000). |
|
629 |
Transcript showCR:(r nextIntegerBetween:1 and:1000000). |
|
630 |
Transcript showCR:(r nextIntegerBetween:1 and:1000000). |
|
631 |
" |
|
632 |
||
633 |
" |
|
680
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
634 |
|r bag| |
3026 | 635 |
r := self new. |
680
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
636 |
bag := Bag new. |
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
637 |
1000000 timesRepeat:[ |
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
638 |
bag add:(r nextIntegerBetween:-1 and:1). |
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
639 |
]. |
3134 | 640 |
Transcript showCR:bag sortedCounts. |
3026 | 641 |
" |
642 |
||
643 |
" |
|
644 |
|r bag| |
|
645 |
r := self new. |
|
646 |
bag := Bag new. |
|
647 |
1000000 timesRepeat:[ |
|
648 |
bag add:(r nextIntegerBetween:1 and:3). |
|
649 |
]. |
|
3134 | 650 |
Transcript showCR:bag sortedCounts. |
3026 | 651 |
TestCase assert:(bag standardDeviation closeTo:(((3 squared - 1)/12) sqrt)). |
652 |
" |
|
653 |
||
654 |
" |
|
655 |
|r bag| |
|
656 |
r := self new. |
|
657 |
bag := Bag new. |
|
658 |
1000000 timesRepeat:[ |
|
3134 | 659 |
bag add:(r nextIntegerBetween:1 and:32). |
3026 | 660 |
]. |
3134 | 661 |
Transcript showCR:bag sortedCounts. |
662 |
TestCase assert:(bag standardDeviation closeTo:(((32 squared - 1)/12) sqrt)). |
|
663 |
" |
|
664 |
||
680
a7b98fdac3dc
fixed nextIntegerBetween:and:
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
665 |
" |
3134 | 666 |
|r bag| |
667 |
r := self new. |
|
668 |
bag := Bag new. |
|
669 |
100000000 timesRepeat:[ |
|
670 |
bag add:(r nextIntegerBetween:1 and:400000). |
|
671 |
]. |
|
672 |
Transcript showCR:bag sortedCounts. |
|
673 |
TestCase assert:(bag standardDeviation closeTo:(((400000 squared - 1)/12) sqrt)). |
|
674 |
" |
|
675 |
||
3675 | 676 |
" |
677 |
|r| |
|
678 |
||
679 |
r := self new. |
|
680 |
100000000 timesRepeat:[ |
|
681 |
self assert:((r nextIntegerBetween:1 and:3) between:1 and:3). |
|
682 |
]. |
|
683 |
" |
|
3750 | 684 |
! |
685 |
||
686 |
nextLettersOrDigits:count |
|
4600 | 687 |
"get a random string consisting of count printable letters or digits [0-9A-Za-z]." |
3750 | 688 |
|
689 |
|res cnt "{ Class:SmallInteger }"| |
|
690 |
||
691 |
cnt := count. |
|
692 |
res := String uninitializedNew:cnt. |
|
693 |
||
694 |
1 to:cnt do:[:i| |
|
695 |
self step. |
|
696 |
res |
|
697 |
at:i |
|
698 |
put:('1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' at:(seed \\ 62 + 1)). |
|
699 |
]. |
|
700 |
||
701 |
^ res |
|
702 |
||
703 |
" |
|
4600 | 704 |
Random new nextLettersOrDigits:40 |
3750 | 705 |
" |
0 | 706 |
! ! |
707 |
||
65 | 708 |
!Random methodsFor:'blocked methods'! |
0 | 709 |
|
65 | 710 |
contents |
711 |
"blocked from use - contents makes no sense for random generators" |
|
712 |
||
713 |
self shouldNotImplement |
|
714 |
! |
|
715 |
||
716 |
nextPut: value |
|
717 |
"blocked from use - it makes no sense for randoms" |
|
718 |
||
719 |
self shouldNotImplement |
|
720 |
! ! |
|
721 |
||
2459 | 722 |
!Random methodsFor:'initialization'! |
723 |
||
724 |
initialize |
|
725 |
self setSeed |
|
726 |
! ! |
|
727 |
||
65 | 728 |
!Random methodsFor:'private'! |
0 | 729 |
|
2430 | 730 |
addEntropy:entropyBytes |
731 |
"add some entropy - ignored here" |
|
732 |
||
733 |
^ self |
|
734 |
! |
|
735 |
||
2291 | 736 |
seed |
737 |
^ seed |
|
738 |
! |
|
739 |
||
0 | 740 |
setSeed |
3134 | 741 |
"set the initial seed value based on the current time and processId. |
742 |
These numbers implement a maximum period generator which passes |
|
743 |
the spectral test for randomness for dimensions 2 3 4 5 6 and |
|
744 |
the product does not overflow 2 raisedTo:29. |
|
745 |
||
746 |
Use both time and processId for seed, to make different processes |
|
747 |
return different Random numbers" |
|
748 |
||
749 |
|newSeed| |
|
750 |
||
751 |
RandomSalt isNil ifTrue:[ |
|
752 |
RandomSalt := 1. |
|
753 |
] ifFalse:[ |
|
754 |
RandomSalt := RandomSalt + 1. |
|
755 |
]. |
|
756 |
newSeed := RandomSalt + (Time millisecondClockValue bitXor:OperatingSystem getProcessId). |
|
757 |
self setSeed:newSeed. |
|
758 |
||
759 |
"Modified: / 29-05-2007 / 12:07:37 / cg" |
|
760 |
! |
|
761 |
||
762 |
setSeed:seedValue |
|
4600 | 763 |
"set the initial seed and intialize the PRNG parameters." |
842 | 764 |
|
4600 | 765 |
self subclassResponsibility. |
517
4e47b198c9bc
allow multiplier, increment & modulus to be changed.
Claus Gittinger <cg@exept.de>
parents:
350
diff
changeset
|
766 |
|
1878 | 767 |
"Modified: / 12-11-1999 / 17:50:52 / stefan" |
768 |
"Created: / 26-05-2007 / 21:25:10 / cg" |
|
517
4e47b198c9bc
allow multiplier, increment & modulus to be changed.
Claus Gittinger <cg@exept.de>
parents:
350
diff
changeset
|
769 |
! |
4e47b198c9bc
allow multiplier, increment & modulus to be changed.
Claus Gittinger <cg@exept.de>
parents:
350
diff
changeset
|
770 |
|
4e47b198c9bc
allow multiplier, increment & modulus to be changed.
Claus Gittinger <cg@exept.de>
parents:
350
diff
changeset
|
771 |
step |
4e47b198c9bc
allow multiplier, increment & modulus to be changed.
Claus Gittinger <cg@exept.de>
parents:
350
diff
changeset
|
772 |
"compute the next random integer" |
4e47b198c9bc
allow multiplier, increment & modulus to be changed.
Claus Gittinger <cg@exept.de>
parents:
350
diff
changeset
|
773 |
|
4600 | 774 |
self subclassResponsibility |
0 | 775 |
! ! |
65 | 776 |
|
142 | 777 |
!Random methodsFor:'testing'! |
778 |
||
779 |
atEnd |
|
780 |
"instances of Random can always give more numbers" |
|
781 |
||
782 |
^ false |
|
783 |
! |
|
784 |
||
785 |
isReadable |
|
786 |
^ true |
|
517
4e47b198c9bc
allow multiplier, increment & modulus to be changed.
Claus Gittinger <cg@exept.de>
parents:
350
diff
changeset
|
787 |
! |
4e47b198c9bc
allow multiplier, increment & modulus to be changed.
Claus Gittinger <cg@exept.de>
parents:
350
diff
changeset
|
788 |
|
4e47b198c9bc
allow multiplier, increment & modulus to be changed.
Claus Gittinger <cg@exept.de>
parents:
350
diff
changeset
|
789 |
isWritable |
3781 | 790 |
"return true, if writing is supported by the receiver. |
791 |
Random Generators never are" |
|
792 |
||
517
4e47b198c9bc
allow multiplier, increment & modulus to be changed.
Claus Gittinger <cg@exept.de>
parents:
350
diff
changeset
|
793 |
^ false |
4e47b198c9bc
allow multiplier, increment & modulus to be changed.
Claus Gittinger <cg@exept.de>
parents:
350
diff
changeset
|
794 |
|
4e47b198c9bc
allow multiplier, increment & modulus to be changed.
Claus Gittinger <cg@exept.de>
parents:
350
diff
changeset
|
795 |
"Created: 1.4.1997 / 22:38:27 / cg" |
4600 | 796 |
! |
797 |
||
798 |
maxInteger |
|
799 |
"the max value returned by self nextInteger" |
|
800 |
||
801 |
self subclassResponsibility |
|
142 | 802 |
! ! |
803 |
||
804 |
!Random class methodsFor:'documentation'! |
|
805 |
||
806 |
version |
|
3675 | 807 |
^ '$Header$' |
2291 | 808 |
! |
809 |
||
810 |
version_CVS |
|
3675 | 811 |
^ '$Header$' |
142 | 812 |
! ! |
3026 | 813 |