Random
Inherits from: Object
Random number generation with both class-level and instance-level APIs.
Class methods use a global auto-seeded source — convenient for general use. Instance methods use a per-instance generator, optionally seeded for reproducible sequences.
Test
(Random next) < 1.0 >>> true
(Random next) > -1.0 >>> true
(Random nextInt: 1) = 0 >>> true
(Random nextBetween: 5 and: 5) >>> 5
(Random new: 42) nextInt: 1000 >>> (Random new: 42) nextInt: 1000
(Random new: 99) next < 1.0 >>> true
Example
"Roll a six-sided die"
Random nextInt: 6
Example
"Reproducible sequence"
| r <Random> |
r := Random new: 42.
r nextInt: 100
Class Methods
primitives
class new
class new:
class next
class nextBetween:and:
class nextInt:
Instance Methods
primitives
next
nextBetween:and:
nextInt:
uncategorized
printString
Return a human-readable string representation.