Class in random coil-stdlib

Rng

class Rng
Import
use random::{Rng};
Source: src/random.hy

A seeded pseudo-random number generator.

The same seed always gives the same sequence, which makes tests repeatable. It is not cryptographically secure: for keys, tokens and nonces use crypto::random_bytes from coil-crypto. from_time needs the coil-time package on the module roots.

Associated functions#

NameDescription
seededCreates a generator from seed.
from_timeCreates a generator seeded from the current wall-clock and monotonic time (via coil-time).

Methods#

NameDescription
next_u64Returns the next raw value from the generator, a non-negative int.
rangeReturns a value in lo..hi (including lo, excluding hi), or lo when hi <= lo.
floatReturns a float in 0.0..1.0.
bytesReturns n pseudo-random bytes (none when n <= 0).

Examples#

use random::{Rng};
use tests::assert;
let a = Rng::seeded(7);
let b = Rng::seeded(7);
assert!(a.range(0, 100) == b.range(0, 100));
let roll = a.range(1, 7);
assert!(roll >= 1 && roll < 7);

See also#

↑ ↓ navigate ↵ open