pub struct LibQRng { /* private fields */ }Expand description
Main libQ random number generator
This is the primary RNG implementation for the libQ ecosystem, providing a unified interface for secure random number generation across different platforms and use cases.
Implementations§
Source§impl LibQRng
impl LibQRng
Sourcepub fn new_secure() -> Result<Self>
pub fn new_secure() -> Result<Self>
Create a new secure RNG using the best available entropy source
This method creates a cryptographically secure RNG using the highest quality entropy source available on the current platform.
§Errors
Returns an error if no secure entropy source is available.
§Examples
use lib_q_random::LibQRng;
use rand_core::Rng;
let mut rng = LibQRng::new_secure().unwrap();
let mut bytes = [0u8; 32];
rng.fill_bytes(&mut bytes);Sourcepub fn new_deterministic(seed: [u8; 32]) -> Self
pub fn new_deterministic(seed: [u8; 32]) -> Self
Create a new deterministic RNG for testing
Initializes a ChaCha20 byte stream from a 256-bit seed (same as
rand_chacha::ChaCha20Rng::from_seed). Suitable for KATs and regression
tests. Unpredictability is only as strong as the seed: this is not a
substitute for Self::new_secure in production.
§Arguments
seed- 32-byteChaCha20key material; must be chosen explicitly for tests
§Examples
use lib_q_random::LibQRng;
use rand_core::Rng;
let mut rng = LibQRng::new_deterministic([1; 32]);
let mut bytes = [0u8; 32];
rng.fill_bytes(&mut bytes);Sourcepub fn new_custom<T: EntropySource + 'static>(entropy_source: T) -> Self
pub fn new_custom<T: EntropySource + 'static>(entropy_source: T) -> Self
Create a new RNG with a custom entropy source
This method allows creating an RNG with a custom entropy source, useful for specialized applications or testing.
§Arguments
entropy_source- Custom entropy source implementation
§Examples
use lib_q_random::LibQRng;
use lib_q_random::entropy::UserEntropySource;
use rand_core::Rng;
let entropy_data = vec![1, 2, 3, 4, 5, 6, 7, 8];
let entropy_source = UserEntropySource::new(entropy_data);
let mut rng = LibQRng::new_custom(entropy_source);Sourcepub fn with_config(config: &RngConfig) -> Result<Self>
pub fn with_config(config: &RngConfig) -> Result<Self>
Create a new RNG with custom configuration
This method allows creating an RNG with specific configuration parameters for specialized use cases.
§Arguments
config- RNG configuration parameters
§Errors
Returns an error if the configuration is invalid or if the RNG cannot be created with the specified parameters.
Sourcepub fn is_deterministic(&self) -> bool
pub fn is_deterministic(&self) -> bool
Check if this RNG is deterministic
Sourcepub fn security_level(&self) -> SecurityLevel
pub fn security_level(&self) -> SecurityLevel
Get the security level of this RNG
Sourcepub fn entropy_source_name(&self) -> &'static str
pub fn entropy_source_name(&self) -> &'static str
Get the entropy source name
Sourcepub fn entropy_source_type(&self) -> EntropySourceType
pub fn entropy_source_type(&self) -> EntropySourceType
Get the entropy source type
Sourcepub fn reseed_counter(&self) -> u32
pub fn reseed_counter(&self) -> u32
Get the reseed counter
Sourcepub fn bytes_generated(&self) -> usize
pub fn bytes_generated(&self) -> usize
Get the bytes generated since last reseed
Sourcepub fn entropy_quality(&self) -> f64
pub fn entropy_quality(&self) -> f64
Get the entropy quality estimate (0.0 to 1.0)
Source§impl LibQRng
impl LibQRng
Sourcepub fn fill<T>(&mut self, dest: &mut [T])
pub fn fill<T>(&mut self, dest: &mut [T])
Fill a slice with random values of any integer type
This method provides a convenient way to fill slices of different integer types with random values, handling the byte conversion internally.
§Examples
use lib_q_random::LibQRng;
let mut rng = LibQRng::new_secure().unwrap();
let mut u16_array = [0u16; 10];
rng.fill(&mut u16_array);Trait Implementations§
Source§impl SecureRng for LibQRng
Available on crate feature alloc only.
impl SecureRng for LibQRng
alloc only.Source§fn fill_bytes_secure(&mut self, dest: &mut [u8]) -> Result<()>
fn fill_bytes_secure(&mut self, dest: &mut [u8]) -> Result<()>
Source§fn next_u32_secure(&mut self) -> Result<u32>
fn next_u32_secure(&mut self) -> Result<u32>
Source§fn next_u64_secure(&mut self) -> Result<u64>
fn next_u64_secure(&mut self) -> Result<u64>
Source§fn initialize(&mut self, entropy: &[u8]) -> Result<()>
fn initialize(&mut self, entropy: &[u8]) -> Result<()>
Source§fn entropy_quality(&self) -> f64
fn entropy_quality(&self) -> f64
Source§fn security_level(&self) -> SecurityLevel
fn security_level(&self) -> SecurityLevel
Source§fn state_size(&self) -> usize
fn state_size(&self) -> usize
Source§impl TryRng for LibQRng
Available on crate feature alloc only.
impl TryRng for LibQRng
alloc only.Source§type Error = Infallible
type Error = Infallible
impl TryCryptoRng for LibQRng
alloc only.