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

#989 in Algorithms

Download history 15102/week @ 2023-12-13 11503/week @ 2023-12-20 9292/week @ 2023-12-27 15448/week @ 2024-01-03 16242/week @ 2024-01-10 17711/week @ 2024-01-17 16299/week @ 2024-01-24 16663/week @ 2024-01-31 11829/week @ 2024-02-07 12829/week @ 2024-02-14 17512/week @ 2024-02-21 20815/week @ 2024-02-28 18212/week @ 2024-03-06 18413/week @ 2024-03-13 17611/week @ 2024-03-20 15051/week @ 2024-03-27

73,533 downloads per month
Used in 129 crates (12 directly)

MIT license

9KB
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

~73KB