#rand #pseudo #random #std #atomics

quad-rand

Pseudo random implementation with std atomics

4 releases

0.2.1 Feb 15, 2021
0.2.0 Jan 20, 2021
0.1.1 Apr 18, 2020
0.1.0 Apr 18, 2020

#143 in WebAssembly

Download history 377/week @ 2020-12-23 275/week @ 2020-12-30 171/week @ 2021-01-06 206/week @ 2021-01-13 323/week @ 2021-01-20 191/week @ 2021-01-27 261/week @ 2021-02-03 178/week @ 2021-02-10 226/week @ 2021-02-17 236/week @ 2021-02-24 265/week @ 2021-03-03 454/week @ 2021-03-10 539/week @ 2021-03-17 223/week @ 2021-03-24 248/week @ 2021-03-31 428/week @ 2021-04-07

1,077 downloads per month
Used in 10 crates (via macroquad)

MIT license

8KB
182 lines

quad-rand

Crates.io version Documentation on docs.rs

quad-rand implements pseudo-random generator http://www.pcg-random.org/download.html based on rust atomics.

Compatible with wasm and any other rust target with std.

Basic usage, no dependencies involved:

use quad_rand as qrand;

// seed random
qrand::srand(12345);

// get random number from 0 to u32::MAX
let x = qrand::rand();

// get random number from given range
let x = qrand::gen_range(0., 1.);
assert!(x >= 0. && x < 1.);

// gen_range works for most of standart number types
let x: u8 = qrand::gen_range(64, 128);
assert!(x >= 64 && x < 128);

Optional compatibility layer with rand crate:

use quad_rand::compat::QuadRand;
use rand::seq::SliceRandom;

let mut vec = vec![1, 2, 3, 4, 5, 6];

// QuadRand is rand::RngCore implementation, allowing to use all the cool stuff from rand
vec.shuffle(&mut QuadRand);

Dependencies

~76KB