Random
Seedable random number generators.
Always available
No import needed. These names are in scope in every file.
Random class
ts
class RandomSeedable PRNG with deterministic output for a given seed. fork(name) derives a child from the original seed and name, making sibling branches order-independent.
Random.seed
ts
readonly seed: float64The seed used to initialize this instance.
new Random()
ts
constructor(seed?: float64)Create a new Random instance.
Parameters
seed: Optional seed value (float64); if omitted, seeded from system clock.
Random.fork
ts
fork(): Random
fork(name: string): RandomCreate a child Random instance derived from this instance's current state.
Returns: A new Random that advances this instance.
Random.next
ts
next(): float64Return a pseudorandom float in [0.0, 1.0).
Returns: A float >= 0.0 and < 1.0.
Random.nextBool
ts
nextBool(): booleanReturn a pseudorandom boolean with roughly 50% probability of true.
Returns: true or false.
Random.nextFloat
ts
nextFloat(min: float64, max: float64): float64Return a pseudorandom float in [min, max).
Parameters
min: Minimum (inclusive).max: Maximum (exclusive).
Returns: A float >= min and < max.
Random.nextInt
ts
nextInt(min: int, max: int): intReturn a pseudorandom integer in [min, max].
Parameters
min: Minimum (inclusive).max: Maximum (inclusive).
Returns: An integer >= min and <= max.
Random.pick
ts
pick(array: Array<any>): anyReturn a random element from an array.
Parameters
array: The array to pick from.
Returns: An element chosen uniformly at random, or undefined if the array is empty.
Random.shuffle
ts
shuffle(array: Array<any>): Array<any>Return a new array with elements randomly shuffled using Fisher-Yates.
Parameters
array: The array to shuffle (not modified).
Returns: A new array with shuffled elements.
Random.weighted
ts
weighted(weights: Array<float64>): intReturn an index selected by weighted probability distribution.
Parameters
weights: Array of non-negative weights; higher weight = higher probability.
Returns: An index (0 to weights.length - 1) selected by the weights.
Generated from lang/types/builtin_random.d.tks in the ThicketScript repository.