Module random

Module random 

Source

Macros§

define_rng
Use this to define a unique type which will be used as a key to retrieve an independent rng instance when calling Context::get_rng.

Traits§

ContextRandomExt
RngId

Functions§

count_and_sample_single_l_reservoir
Count elements and sample one element uniformly from an iterator of unknown length.
sample_multiple_from_known_length
Samples requested elements uniformly at random without replacement from an iterator whose length is known at runtime. Requires len >= requested.
sample_multiple_l_reservoir
Sample multiple random elements uniformly without replacement from a container of unknown length. If more samples are requested than are in the set, the function returns as many items as it can.
sample_single_excluding
Samples one element uniformly at random from slice, excluding any element equal to excluded. Returns None if the slice is empty or every element equals excluded.
sample_single_excluding_iteration
Linear-scan implementation of sample_single_excluding. Counts non-excluded entries, then picks the k-th. Wins for very small slices (n <= 3) where the per-trial overhead of rejection sampling exceeds the cost of a tiny filter. Exposed so benchmarks can compare strategies directly.
sample_single_excluding_l_reservoir
Sample one element uniformly from an iterator, excluding any element equal to excluded. Returns None if the iterator is empty or every element equals excluded.
sample_single_excluding_rejection
Rejection-sampling implementation of sample_single_excluding. Picks a uniform index, accepts if not equal to excluded. Wins at n >= 4 and is essentially constant time when excluded appears 0 or 1 times. Falls through to sample_single_excluding_iteration after at most 16 consecutive matches (or n, whichever is smaller), which also returns None when every element matches. Exposed so benchmarks can compare strategies directly.
sample_single_from_known_length
Samples one element uniformly at random from an iterator whose length is known at runtime.
sample_single_l_reservoir
Sample a random element uniformly from an iterator of unknown length.