Expand description
This Rust crate contains implementation of common random number generation functions. All functions and types from this crate supply cryptographically secure random numbers.
Instead of relying on external crates, all HOPR crates in this monorepo should
exclusively rely on randomness functions only from this crate.
Besides that, the OsRng
type exported from this crate can be used if a type implementing
random traits is necessary.
Constants§
- MAX_
RANDOM_ INTEGER - Maximum random integer that can be generated. This is the last positive 64-bit value in the two’s complement representation.
Traits§
- Rng
- An automatically-implemented extension trait on
RngCore
providing high-level generic methods for sampling values and other convenience methods. - RngCore
- The core of a random number generator.
Functions§
- is_
rng_ fixed - Returns
true
if the build is using an insecure RNG with a fixed seed. - random_
array - Allocates
GenericArray
of the given size and fills it with random bytes - random_
bytes - Allocates an array of the given size and fills it with random bytes
- random_
fill - Fills the specific number of bytes starting from the given offset in the given buffer.
- random_
float - Generates a random float uniformly distributed between 0 (inclusive) and 1 (exclusive).
- random_
float_ in_ range - Generates a random float uniformly distributed in the given range.
- random_
integer - Generates a random unsigned integer which is at least
start
and optionally strictly less thanend
. Ifend
is not given, theMAX_RANDOM_INTEGER
value is used. The caller must make sure that 0 <=start
<end
<=MAX_RANDOM_INTEGER
, otherwise the function will panic. - rng
- Gets the default cryptographically secure random number generator.