quad-rand

Crates.ioquad-rand
lib.rsquad-rand
version0.2.3
sourcesrc
created_at2020-04-18 13:39:59.882607
updated_at2024-11-06 02:53:28.953202
descriptionPseudo random implementation with core atomics.
homepagehttps://github.com/not-fl3/quad-rand
repositoryhttps://github.com/not-fl3/quad-rand
max_upload_size
id231521
size15,891
Fedor Logachev (not-fl3)

documentation

README

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 also no-std compatible.

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 standard 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);

Commit count: 14

cargo fmt