#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

#190 in Algorithms

Download history 26684/week @ 2024-10-24 23017/week @ 2024-10-31 24209/week @ 2024-11-07 20088/week @ 2024-11-14 23587/week @ 2024-11-21 17319/week @ 2024-11-28 19153/week @ 2024-12-05 18492/week @ 2024-12-12 11841/week @ 2024-12-19 8004/week @ 2024-12-26 15472/week @ 2025-01-02 17839/week @ 2025-01-09 19327/week @ 2025-01-16 16251/week @ 2025-01-23 20650/week @ 2025-01-30 21913/week @ 2025-02-06

81,973 downloads per month
Used in 214 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy