/rng
Pseudo-random number generation for bounded integers, floats, booleans, and collection sampling.
Functions & symbols#
choose#
Uniformly selects a single element from a collection, or returns `()` if empty.
| Parameter | Type | Optional | Description |
|---|---|---|---|
coll | Any | required | Sequence, Range, Slab, String, Set, or Map |
Any(rng/choose [:a :b :c])(rng/choose 1..=6)random-bool#
Generates a random Bool with fair 50/50 odds or Bernoulli probability `p` in `0.0..=1.0`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
p | Float | required | Optional Bernoulli probability in `0.0..=1.0` (defaults to `0.5`) |
Any(rng/random-bool)(rng/random-bool 0.25)random-float#
Generates a uniform random Float in `[0.0, 1.0)`, `[0.0, end)`, `[start, end)`, or a Range.
| Parameter | Type | Optional | Description |
|---|---|---|---|
end-or-range | Any | required | Optional upper bound `end > 0.0` or float `Range` (e.g. `-1.0..1.0`) |
end | Float | required | Optional exclusive upper bound when `start` is provided |
Any(rng/random-float)(rng/random-float 10.0)(rng/random-float -1.0..1.0)random-int#
Generates a uniform random Int in `[0, end)`, `[start, end)`, or from an integer Range.
| Parameter | Type | Optional | Description |
|---|---|---|---|
end-or-range | Any | required | Exclusive upper bound `end > 0` or integer `Range` (e.g. `1..=6`, `0..=100|5`) |
end | Int | required | Optional exclusive upper bound when `start` is provided |
Any(rng/random-int 100)(rng/random-int 10 20)(rng/random-int 1..=6)sample#
Samples `k` distinct elements without replacement in random order, clamping `k`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
coll | Any | required | Sequence, Range, Slab, String, Set, or Map |
k | Int | required | Number of distinct elements to sample (clamped to `0..(count-of coll)`) |
Any(rng/sample [1 2 3 4 5] 3)(rng/sample 1..=52 5)shuffle#
Returns a new collection with its elements shuffled in uniformly random order.
| Parameter | Type | Optional | Description |
|---|---|---|---|
coll | Any | required | Sequence, Range, Slab, String, Set, or Map |
Any(rng/shuffle [1 2 3 4 5])shuffle<-#
Shuffles a mutable collection in place using Fisher-Yates and returns the mutated collection.
| Parameter | Type | Optional | Description |
|---|---|---|---|
coll | #mut Any | required | Mutable Array, Int-Array, Float-Array, Dec-Array, Slab, or Map |
Any(let #mut deck [1 2 3 4]) (rng/shuffle<- deck)