Expand description
§CLRRandom
A Rust implementation of the .NET CLR Random number generator that is
compatible with no_std environments.
This library provides a deterministic pseudo-random number generator that
produces the same sequence of numbers as the .NET Framework’s System.Random
class when initialized with the same seed. This is useful for cross-platform
applications that need to maintain compatibility with .NET implementations.
Note on Compatibility: Only the methods [next_i32] (equivalent to .NET’s Next()),
fill_bytes (equivalent to .NET’s NextBytes()), and next_f64 (equivalent to .NET’s NextDouble())
are guaranteed to exhibit exact behavior matching the .NET implementation.
§Features
no_stdcompatible- Deterministic output matching .NET CLR
System.Random - Minimal dependencies
- Simple and efficient API
§Security Warning
This generator is NOT cryptographically secure. Do not use it for security-sensitive applications such as:
- Generating cryptographic keys
- Creating authentication tokens
- Security-critical random values
§Installation
[dependencies]
clr_random = "0.1.0"§Quick Start
use clr_random::{CLRRandom, Seed};
use rand_core::{RngCore, SeedableRng};
// Create a new generator from a 32-bit seed.
let mut rng = CLRRandom::from_seed(0.into());
// Generate a random number.
let num1 = rng.next_i32();
// The generated numbers are deterministic.
let mut rng2 = CLRRandom::from_seed(0.into());
assert_eq!(num1, rng2.next_i32());
assert_eq!(num1, 1559595546);Re-exports§
pub use rand_core;