6 releases

0.2.3 Nov 6, 2024
0.2.2 Sep 7, 2024
0.2.1 Feb 15, 2021
0.2.0 Jan 20, 2021
0.1.1 Apr 18, 2020

#106 in Algorithms

Download history 20641/week @ 2025-01-30 21933/week @ 2025-02-06 20988/week @ 2025-02-13 24183/week @ 2025-02-20 23684/week @ 2025-02-27 25026/week @ 2025-03-06 24516/week @ 2025-03-13 27305/week @ 2025-03-20 25259/week @ 2025-03-27 95161/week @ 2025-04-03 183260/week @ 2025-04-10 77616/week @ 2025-04-17 82964/week @ 2025-04-24 111410/week @ 2025-05-01 136419/week @ 2025-05-08 92973/week @ 2025-05-15

442,155 downloads per month
Used in 234 crates (13 directly)

MIT license

11KB
226 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 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);

Dependencies

~78KB