Expand description
PureRng is a rand-compatible RNG library
for generating repeatable, controlled random values, designed primarily for
use in games. It uses a hash function to generate exactly one random value
per seed. A convenient API is provided to distribute seed values throughout
your program in a hierarchical fashion.
§Usage
use pure_rng::prelude::*;
// Create the root rng using an initial seed, typically from an external source.
let rng = PureRng::new(1234);
// Seed two more RNGs with arbitrary labels.
// These effectively have their seed appended to that of the parent.
let rng_a = rng.seed("a convenient label");
let rng_b = rng.seed("a different label");
// Generate a value from the first RNG, consuming it.
let value_a: u32 = rng_a.random();
// Create two more forks of the second RNG, and generate values from them inline.
let value_b1: i64 = rng_b.seed(1).random();
let value_b2: f64 = rng_b.seed(2).random();
// Use your custom types
#[derive(Hash)]
struct Point { x: i32, y: i32 }
let value_from_point: u64 = rng
.seed(Point { x: 10, y: 12 })
.random();
// Use the all the usual `rand` API features
let character = rng
.seed("character")
.sample(rand::distr::Alphanumeric) as char;For more information see the README, the accompanying blog post, and the examples
Modules§
Structs§
- Pure
Random Generator - Generic RNG type over any Hasher
Type Aliases§
- PureRng
- Default generator using Rapidhash