random API

← random · version 0.3.6

7 public items, in source order. Generated from the registry index, which re-derives them from the package source at publish time — so a signature here is the one that version actually ships.

pub fn rand(lo: integer, hi: integer) -> integer?

Returns a random integer in [lo, hi] (inclusive). Returns null when lo > hi or when either argument is null. Draws from the ONE hidden generator every call site shares — see rand_seed.

pub fn rand_seed(seed: integer)

Seeds the thread-local random number generator with the given value. Call this before rand() or rand_indices() to get reproducible sequences — but note that it fixes what the GENERATOR produces, not what you receive: it is shared, so one rand() from anywhere else shifts everything after it. When reproducibility is a requirement rather than a convenience, own a stream.

pub fn rand_indices(n: integer) -> vector<integer>

Returns a vector of n integers [0, 1, ..., n-1] in a random order. Useful for random iteration, shuffling, or sampling without replacement. Returns an empty vector when n is 0, negative or null.

pub struct RandStream { s1: integer, s2: integer }

An independent random stream: the two Lehmer generator states. Seed one with seed_stream and draw from it with its methods, so its sequence does not depend on any other draw in the program.

pub fn seed_stream(seed: integer) -> RandStream

Seed an independent stream. Any integer seed is valid (negative and zero included); equal seeds give equal streams, different seeds give decorrelated streams.

pub fn get(self: RandStream, lo: integer, hi: integer) -> integer?

A random integer in [lo, hi] (inclusive) from THIS stream, advancing it. Returns null when lo > hi (the same contract as the global rand()).

pub fn indices(self: RandStream, n: integer) -> vector<integer>

A random permutation of [0, 1, ..., n-1] from THIS stream (Fisher-Yates), advancing it by exactly n - 1 draws. Empty when n is 0, negative or null (the same contract as rand_indices()).