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_int(n: i64) -> i64
-
Returns a uniformly-distributed random integer from the half-open interval
[0, n)
— i.e. the interval from zero up to but not includingn
, wheren
is a positive integer.
Classes
-
Generator() -> Generator
-
Returns a new pseudo-random number generator. The generator is 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_int(n: i64) -> i64
-
Returns a uniformly-distributed random integer from the half-open interval
[0, n)
— i.e. the interval from zero up to but not includingn
, wheren
is a positive integer. -
:seed(n: i64)
-
Seeds the generator using the number
n
.