std::prng
This module contains convenience functions for generating pseudo-random numbers using the default pseudo-random number generator (currently a 64-bit Mersenne Twister, initialized with a random seed).
To generate a repeatable sequence of pseudo-random numbers, use a generator from the std::mt64
module.
Functions
-
rand_float() -> f64
-
Returns a uniformly-distributed random float from the half-open interval
[0, 1)
, i.e. the interval from zero up to but not including 1. The generator produces floats with 53 bits of precision. -
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. -
rand_int_in_range(lower: i64, upper: i64) -> i64
-
Returns a uniformly-distributed random integer from the half-open interval
[lower, upper)
, i.e. the interval fromlower
up to but not includingupper
.The arguments can be positive or negative or mixed as long as
lower
is less than or equal toupper
.