Random integers

Uses
- Pseudo-randomness
- Integer intervals
- One-dimensional arrays
- Tuple items

Random integers

A random integer in an interval, plus an updated seed value, can be obtained as:
randomInteger(ℤ⋯ℤ, randomSeed) : (ℤ, randomSeed)
randomInteger(ℕ⋯ℕ, randomSeed) : (ℕ, randomSeed)
randomInteger(ℕ.nz⋯ℕ.nz, randomSeed) : (ℕ.nz, randomSeed)

Random integers are computed in Pharo code:
randomInteger(min: max:, seed:ℕ.nz) ⇒ Pharo:"min ensureNumber. max ensureNumber. seed ensureNumber. (LzRandomTerms signature: signature) integerBetween: min and: max seed: seed" | max min

Example

randomInteger(1 10, seed(1)) ⇒ (8, 42574215097704903886118270442276891296642809153879337352973093820589089894777)

Random integer series

A series of random integers is defined by:
randomIntegers(ℤ⋯ℤ, randomSeed) : RandomSeries(ℤ)

The first item is obtained as:
randomSeriesItem(randomIntegers(interval:ℤ⋯ℤ, seed:randomSeed), 1) ⇒ randomInteger(interval, seed)

Successive items are obtained by iteration:
randomSeriesItem(randomIntegers(interval:ℤ⋯ℤ, seed:randomSeed), n:ℕ.nz) ⇒ randomInteger(interval, second(randomSeriesItem(randomIntegers(interval, seed), n - 1))) | n > 1

Examples

randomIntegers(1 10, seed(1))[1] ⇒ 8

randomIntegers(1 10, seed(1))[2] ⇒ 6

randomIntegers(1 10, seed(1))[3] ⇒ 5