Add references
Add exponential distribution generation
Add xoshiro512+ and xoshiro512++
This library attemps to adapt some common high quality prngs for scientific purposes. Right now xoshiro256+, xoshiro256++, xoshiro512+ and xoshiro512++ are implemented.
Usage:
use prng_hare;
export fn main() void = {
const SEED: u64 = ...;
let rng_x256p = prng_hare::init_xoshiro256p( SEED );
let rand_float = prng_hare::gen_f64(&rng_x256p);
let rng_splitmix = prng_hare::init_splitmix64( SEED );
let SEED: [4]u64 = ...;
let rng_x256pp = prng_hare::init_xoshiro256pp_from_array( SEED );
let rand_u64 = prng_hare::gen_u64(&rng_x256p);
let rand_float = prng_hare::gen_f64(&rng_x256p);
let rng_x512p = prng_hare::init_xoshiro512p( SEED );
let rand_normal_dist = prng_hare::gen_f64_normal(&rng_x512p);
let SEED_8 = [8]u64 = ...;
let rng_x512pp = prng_hare::init_xoshiro512pp_from_array( SEED );
};
All PRNGs provide init_xxx( SEED )
functions which return a variable of type generator.
export type generator = struct {
state: [8]u64,
next: *fn(*[8]u64) u64,
};
The output functions take a pointer to this struct instance as argument.
There are output functions for most numerical types.
Function name | output | notes |
---|---|---|
gen_u64 | u64 | |
gen_u32 | u32 | |
gen_i64 | i64 | |
gen_i32 | i32 | |
gen_f64 | f64 | u64 >> 12 & exponent = 1023 |
gen_f32 | f32 | u64 >> 41 & exponent = 127 |
gen_f64_normal | f64 | Box-Muller transform |
gen_f64_exponential | f64 | Inverse transform |
The gen_f64_normal(*generator, mu: f64, sigma: f64)
function provides normally distributed floats with mean mu
and standard deviation sigma
. The gen_f64_exponential(*generator, lambda: f64)
function produces exponentially distributed floats with rate lambda
.