| Crates.io | tiny-rng |
| lib.rs | tiny-rng |
| version | 0.3.0 |
| created_at | 2019-06-04 23:40:10.577453+00 |
| updated_at | 2025-02-09 07:00:16.549843+00 |
| description | Tiny RNG, a minimal random number generator |
| homepage | |
| repository | https://github.com/JohnBSmith/tiny-rng |
| max_upload_size | |
| id | 139038 |
| size | 18,630 |
Warning: Not cryptographically secure.
Examples:
use tiny_rng::{Rng, Rand};
fn main() {
let mut rng = Rng::from_seed(0);
println!("A u32 random number: 0x{:08x}", rng.rand_u32());
println!("Throw a dice: {}", rng.rand_range_u32(1, 6));
let a: Vec<u32> = rng.iter(Rand::rand_u32).take(4).collect();
println!("An array of u32 random numbers: {:08x?}", a);
let a: Vec<u32> = rng.iter(|rng| rng.rand_range_u32(1, 6))
.take(4).collect();
println!("An array of dice samples: {:?}", a);
let mut a: Vec<u32> = (0..10).collect();
rng.shuffle(&mut a);
println!("A shuffled array: {:?}", a);
let mut a: [u8;4] = [0, 0, 0, 0];
rng.fill(&mut a);
println!("Random bytes: {:?}", a);
}