Rng
class Rng Import
Source: use random::{Rng}; 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#
| Name | Description |
|---|---|
seeded | Creates a generator from seed. |
from_time | Creates a generator seeded from the current wall-clock and monotonic time (via coil-time). |
Methods#
| Name | Description |
|---|---|
next_u64 | Returns the next raw value from the generator, a non-negative int. |
range | Returns a value in lo..hi (including lo, excluding hi), or lo when hi <= lo. |
float | Returns a float in 0.0..1.0. |
bytes | Returns 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);