crates.io docs.rs License: Zlib Tests Average time to resolve an issue Percentage of issues still open Maintenance

nanorand

Current version: 0.7.0

A library meant for fast, random number generation with quick compile time, and minimal dependencies.

Examples

Generating a number with an initialized RNG

```rust use nanorand::{Rng, WyRand};

let mut rng = WyRand::new(); println!("Random number: {}", rng.generate::()); ```

Generating a number with a thread-local RNG

```rust use nanorand::Rng;

let mut rng = nanorand::tls_rng(); println!("Random number: {}", rng.generate::()); ```

Generating a number in a range

```rust use nanorand::{Rng, WyRand};

let mut rng = WyRand::new(); println!("Random number between 1 and 100: {}", rng.generaterange(1u64..=100)); println!("Random number between -100 and 50: {}", rng.generaterange(-100i64..=50)); ```

Buffering random bytes

```rust use nanorand::{Rng, BufferedRng, WyRand};

let mut thingy = [0u8; 5]; let mut rng = BufferedRng::new(WyRand::new()); rng.fill(&mut thingy); // As WyRand generates 8 bytes of output, and our target is only 5 bytes, // 3 bytes will remain in the buffer. assert_eq!(rng.buffered(), 3); ```

Shuffling a Vec

```rust use nanorand::{Rng, WyRand};

let mut rng = WyRand::new(); let mut items = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; rng.shuffle(&mut items); ```

Why should I use this over...

RNG Implementations

RNG|nanorand type|Output Size|Cryptographically Secure|Speed1|Notes|Original Implementation :-----:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----: wyrand|nanorand::WyRand, nanorand::tls::TlsWyRand|64 bits (u64)|🚫|16.4 GB/s||https://github.com/lemire/testingRNG/blob/master/source/wyrand.h Pcg64|nanorand::Pcg64|64 bits (u64)|🚫|1.6 GB/s||https://github.com/rkern/pcg64 ChaCha|nanorand::ChaCha|512 bits ([u32; 16])|✅|204 MB/s (ChaCha8), 79 MB/s (ChaCha20)|Only works in Rust 1.47 or above|https://cr.yp.to/chacha.html

1. Speed benchmarked on an M1 Macbook Air

Entropy Sources

Listed in order of priority

Feature Flags

License

The zlib/libpng License

Copyright (c) 2022 Lucy lucy@absolucy.moe

This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.

  2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.

  3. This notice may not be removed or altered from any source distribution.