#numbers #atomic #compatible

quad-rand

Pseudo random implementation with core atomics

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

#178 in Algorithms

Download history 18812/week @ 2024-10-01 23282/week @ 2024-10-08 26493/week @ 2024-10-15 27784/week @ 2024-10-22 24333/week @ 2024-10-29 22806/week @ 2024-11-05 21952/week @ 2024-11-12 22409/week @ 2024-11-19 18961/week @ 2024-11-26 18641/week @ 2024-12-03 19113/week @ 2024-12-10 16658/week @ 2024-12-17 8198/week @ 2024-12-24 11200/week @ 2024-12-31 17840/week @ 2025-01-07 16506/week @ 2025-01-14

55,810 downloads per month
Used in 201 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

~75KB