pub struct RandomGenerator { /* private fields */ }Expand description
High-level random data generator with stateful RNG.
RandomGenerator provides convenient methods for generating various types of random data
while maintaining an internal RNG state. It implements the RandomGeneratorTemplate trait
for instance methods and provides static methods for one-time generation.
§Usage Patterns
§Stateful Generation
Create a generator once and reuse it for multiple operations:
use product_os_random::{RandomGenerator, RandomGeneratorTemplate};
let mut gen = RandomGenerator::new(None); // Uses default RNG
let bytes1 = gen.get_random_bytes(10);
let bytes2 = gen.get_random_bytes(10);
let number = gen.get_random_usize(1, 100);§One-Time Generation
Use static methods for single random values without maintaining state:
use product_os_random::RandomGenerator;
let password = RandomGenerator::get_simple_random_password_one_time(16);
let alphanumeric = RandomGenerator::get_simple_random_alphanumeric_one_time(10);§Feature-Gated Behavior
- With
coreorsend_only: Can create generator without providing RNG (usesStdRng::from_entropy()) - With
constrainedonly: Must provide an RNG, panics if None given
§Panics
Methods will panic in constrained mode if no RNG is provided. In core or send_only modes,
a default RNG is used when None is provided.
Trait Implementations§
Source§impl Clone for RandomGenerator
impl Clone for RandomGenerator
Source§fn clone(&self) -> RandomGenerator
fn clone(&self) -> RandomGenerator
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl RandomGeneratorTemplate for RandomGenerator
Available on crate feature rand only.
impl RandomGeneratorTemplate for RandomGenerator
Available on crate feature
rand only.Source§fn get_random_bytes(&mut self, len: usize) -> Vec<u8> ⓘ
fn get_random_bytes(&mut self, len: usize) -> Vec<u8> ⓘ
Generates a vector of random bytes. Read more
Source§fn get_random_usize(&mut self, min: usize, max: usize) -> usize
fn get_random_usize(&mut self, min: usize, max: usize) -> usize
Generates a random
usize within the specified range (inclusive). Read moreSource§fn get_random_u32(&mut self) -> u32
fn get_random_u32(&mut self) -> u32
Generates a random
u32. Read moreSource§fn get_random_u64(&mut self) -> u64
fn get_random_u64(&mut self) -> u64
Generates a random
u64. Read moreSource§fn get_random_string(&mut self, len: usize) -> String
fn get_random_string(&mut self, len: usize) -> String
Generates a random string of printable characters. Read more
Source§fn get_random_from_characters(&mut self, len: usize, characters: &str) -> String
fn get_random_from_characters(&mut self, len: usize, characters: &str) -> String
Generates a random string from the provided character set. Read more
Auto Trait Implementations§
impl Freeze for RandomGenerator
impl RefUnwindSafe for RandomGenerator
impl Send for RandomGenerator
impl Sync for RandomGenerator
impl Unpin for RandomGenerator
impl UnsafeUnpin for RandomGenerator
impl UnwindSafe for RandomGenerator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more