std::prng
This module contains utilities for generating pseudo-random numbers using the xoshiro256** algorithm.
The module-level functions use a global generator initialized with a random seed.
To generate a repeatable sequence of pseudo-random numbers, use a Generator instance with a known seed.
Functions
-
rand_float() -> f64 -
Returns a uniformly-distributed random float from the half-open interval
[0.0, 1.0)— i.e. the interval from zero up to but not including1.0. -
rand_float_in_range(x: f64, y: f64) -> f64 -
Returns a uniformly-distributed random float from the half-open interval
[x, y)— i.e. the interval fromxup to but not includingy. The bounds can be positive, negative, or mixed, butxmust be less thany. -
rand_int() -> i64
rand_int(n: i64) -> i64 -
Returns a uniformly-distributed random integer.
-
If called with zero arguments, returns an integer from the full
i64range. -
If called with a single positive integer argument
n, returns an integer from the half-open interval[0, n)— i.e. the interval from zero up to but not includingn.
-
If called with zero arguments, returns an integer from the full
-
rand_int_in_range(n: i64, m: i64) -> i64 -
Returns a uniformly-distributed random integer from the half-open interval
[n, m)— i.e. the interval fromnup to but not includingm. The bounds can be positive, negative, or mixed, butnmust be less thanm.
Classes
-
Generator() -> Generator
Generator(seed: i64) -> Generator -
Returns a new pseudo-random number generator.
If no seed value is specified, the generator will be automatically initialized with a random seed.
Generator instances support the following methods:
-
:rand_float() -> f64 -
Returns a uniformly-distributed random float from the half-open interval
[0.0, 1.0)— i.e. the interval from zero up to but not including1.0. -
:rand_float_in_range(x: f64, y: f64) -> f64 -
Returns a uniformly-distributed random float from the half-open interval
[x, y)— i.e. the interval fromxup to but not includingy. The bounds can be positive, negative, or mixed, butxmust be less thany. -
:rand_int() -> i64
:rand_int(n: i64) -> i64 -
Returns a uniformly-distributed random integer.
-
If called with zero arguments, returns an integer from the full
i64range. -
If called with a single positive integer argument
n, returns an integer from the half-open interval[0, n)— i.e. the interval from zero up to but not includingn.
-
If called with zero arguments, returns an integer from the full
-
:rand_int_in_range(n: i64, m: i64) -> i64 -
Returns a uniformly-distributed random integer from the half-open interval
[n, m)— i.e. the interval fromnup to but not includingm. The bounds can be positive, negative, or mixed, butnmust be less thanm. -
:seed(n: i64) -
Seeds the generator using the number
n.