| Crates.io | rng-pack |
| lib.rs | rng-pack |
| version | 0.4.0 |
| created_at | 2026-01-16 06:47:56.250732+00 |
| updated_at | 2026-01-24 17:55:05.115357+00 |
| description | Random number generator variety pack |
| homepage | |
| repository | |
| max_upload_size | |
| id | 2048027 |
| size | 6,103,612 |
A collection of pseudo-random number generators (PRNGs) implemented in Rust.
This crate provides efficient implementations of various random number generation algorithms, supporting both Rust and C (via FFI).
mt19937::Mt19937 (32-bit)mt1993764::Mt1993764 (64-bit)pcg32::Pcg32 (Permuted Congruential Generator, PCG-XSH-RR)philox32::Philox32 (4x32)philox64::Philox64 (2x64)twisted_gfsr::TwistedGFSRxorshift32::Xorshift32xorshift64::Xorshift64xorshift128::Xorshift128Add this to your Cargo.toml:
[dependencies]
rng_pack = "0.1.0"
use rng_pack::mt19937::Mt19937;
fn main() {
// Initialize with a seed
let mut rng = Mt19937::new(12345);
// Generate a random u32
let val = rng.nextu();
println!("Random u32: {}", val);
// Generate a random float in [0, 1)
let f_val = rng.nextf();
println!("Random f32: {}", f_val);
// Generate a random integer in a range [min, max]
let range_val = rng.randi(1, 100);
println!("Random integer (1-100): {}", range_val);
}
Philox generators produce blocks of random numbers and are suitable for parallel applications.
use rng_pack::philox32::Philox32;
fn main() {
let mut rng = Philox32::new([123, 456]);
// Generates 4 x u32 values at once
let values = rng.nextu();
println!("Random values: {:?}", values);
}
This crate exports C-compatible functions for all generators, allowing them to be used as a shared library.
Each generator exposes functions for:
_new)_free)_next_uXXs, _next_fXXs)_rand_iXXs, _rand_fXXs)Example signature for MT19937:
void* mt19937_new(uint32_t seed);
void mt19937_next_u32s(void* ptr, uint32_t* out, size_t count);
void mt19937_free(void* ptr);