Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
femtorand
High performance random number generators for use in no_std environments.
Uses zero unsafe code.
Basic Usage
use ;
const SEED: u64 = 0xDEADBEEF;
let mut prng = new;
// Generate integers, where all values are equally likely.
// The integer generating functions are generic for:
// u8, u16, u32, u64, usize, i8, i16, i32, i64, isize
assert_eq!;
// Generate int between zero (inclusive) and an upper bound (exclusive).
// Roll a D6.
assert_eq!;
// Generate int between a lower bound (inclusive) and an upper bound (exclusive).
// Roll another D6.
assert_eq!;
// Fill an array.
let mut array = ;
prng.;
assert_eq!;
// Choose from a slice.
let selection: = ;
assert_eq!;
// Flip a coin.
assert_eq!;
Seeds
Initializing a generator requires a seed. Two generators initialized with the same seed will produce the same output.
use ;
const SEED: u64 = 0xDEADBEEF;
let mut prng_one = new;
let mut prng_two = new;
// This holds for an arbitrary number of iterations.
for _ in 0..10
In many applications having a generator produce the same
output for every program invocation is not desirable, but since this crate is intended
to work in a no_std environment it can't know what sources of seed randomness are available to the caller.
In systems utilizing a full desktop operating system,
the OS will generally provide some source of entropy that can be utilized as a seed.
See the getrandom crate for OS randomness sources.
The osseed crate feature will utilize getrandom to seed a generator with OS randomness.
Generators
By default this crate uses the WyRand PRNG, it is invoked when creating a
generator without specifying a type. Lehmer64 is also available.
use ;
const SEED: u64 = 0xDEADBEEF;
let mut wyrand = new;
let mut default_rng = new;
// WyRand is currently configured as the default, but this not a guarantee and may change.
let default_rng_value = default_rng.generate_u128;
assert_eq!;
// A different generator produces different output, even with the same seed.
let mut lehmer = new;
assert_ne!;
Optional features
Support for floating point
Using the float crate feature adds support for generation of
floating point values and booleans with adjustable distribution.
It is enabled by default.
Support for seeding from OS random
The osseed crate feature allows a generator to be automatically seeded from
the OS entropy source.