equal
deleted
inserted
replaced
147 Transcript showCR:(Random nextBetween:1 and:100). |
147 Transcript showCR:(Random nextBetween:1 and:100). |
148 " |
148 " |
149 |
149 |
150 "Modified: 21.8.1997 / 18:08:56 / cg" |
150 "Modified: 21.8.1997 / 18:08:56 / cg" |
151 "Created: 21.8.1997 / 18:09:36 / cg" |
151 "Created: 21.8.1997 / 18:09:36 / cg" |
|
152 ! |
|
153 |
|
154 nextBoolean |
|
155 "return a boolean random. |
|
156 This method behaves like the corresponding instance method, |
|
157 but allows generation of random numbers without |
|
158 a need for an instance of Random to be kept around. |
|
159 This uses a common, shared generator." |
|
160 |
|
161 RandomGenerator isNil ifTrue:[ |
|
162 RandomGenerator := self new. |
|
163 ]. |
|
164 ^ RandomGenerator nextBoolean. |
|
165 |
|
166 " |
|
167 Transcript showCR:(Random nextBoolean). |
|
168 Transcript showCR:(Random nextBoolean). |
|
169 Transcript showCR:(Random nextBoolean). |
|
170 Transcript showCR:(Random nextBoolean). |
|
171 " |
|
172 |
|
173 "Created: 21.8.1997 / 18:08:23 / cg" |
152 ! |
174 ! |
153 |
175 |
154 nextInteger |
176 nextInteger |
155 "return an integral random number. |
177 "return an integral random number. |
156 This method behaves like the corresponding instance method, |
178 This method behaves like the corresponding instance method, |
312 ! |
334 ! |
313 |
335 |
314 nextBoolean |
336 nextBoolean |
315 "return true or false by random" |
337 "return true or false by random" |
316 |
338 |
317 ^ self nextInteger < (modulus / 2) |
339 ^ self next < 0.5 |
318 |
340 |
319 "|r| |
341 "|r| |
320 r := Random new. |
342 r := Random new. |
321 Transcript showCR:r nextBoolean. |
343 Transcript showCR:r nextBoolean. |
322 Transcript showCR:r nextBoolean. |
344 Transcript showCR:r nextBoolean. |
499 ! ! |
521 ! ! |
500 |
522 |
501 !Random class methodsFor:'documentation'! |
523 !Random class methodsFor:'documentation'! |
502 |
524 |
503 version |
525 version |
504 ^ '$Header: /cvs/stx/stx/libbasic2/Random.st,v 1.24 1999-11-12 16:51:04 stefan Exp $' |
526 ^ '$Header: /cvs/stx/stx/libbasic2/Random.st,v 1.25 1999-12-10 02:02:43 cg Exp $' |
505 ! ! |
527 ! ! |