#numbers #atomic #compatible

quad-rand

Pseudo random implementation with core atomics

6 releases

new 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

#101 in Algorithms

Download history 18518/week @ 2024-07-19 19452/week @ 2024-07-26 17677/week @ 2024-08-02 17547/week @ 2024-08-09 17985/week @ 2024-08-16 18825/week @ 2024-08-23 17547/week @ 2024-08-30 19274/week @ 2024-09-06 18026/week @ 2024-09-13 19716/week @ 2024-09-20 18705/week @ 2024-09-27 20788/week @ 2024-10-04 26512/week @ 2024-10-11 27493/week @ 2024-10-18 25710/week @ 2024-10-25 18356/week @ 2024-11-01

103,131 downloads per month
Used in 167 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

~74KB