pub struct SecureRng { /* private fields */ }Expand description
A cryptographically secure random number generator.
The current implementation is Chacha with 8 rounds, using the original variation
(64-bit counter). This allows for 1 ZiB (270 bytes) of output
before cycling. That’s over 147 quintillion calls to SecureRng::u64.
Trait Implementations§
Source§impl SecureYARandGenerator for SecureRng
impl SecureYARandGenerator for SecureRng
Source§fn fill_bytes(&mut self, dst: &mut [u8])
fn fill_bytes(&mut self, dst: &mut [u8])
Fills
dst with random data, which is safe to be used in cryptographic contexts. Read moreSource§fn text<E: Encoder>(&mut self, len: usize) -> Option<String>
fn text<E: Encoder>(&mut self, len: usize) -> Option<String>
Generates a random
String with length len, using the provided
Encoder to determine character set and minimum secure length. Since
character sets can only contain valid ascii values, the length of the created
String reprensents both the size of the String in bytes, and the
amount of characters it contains. Read moreSource§impl YARandGenerator for SecureRng
impl YARandGenerator for SecureRng
Source§fn try_new() -> Result<Self, Error>
fn try_new() -> Result<Self, Error>
Creates a generator using randomness provided by the OS. Read more
Source§fn bool(&mut self) -> bool
fn bool(&mut self) -> bool
A simple coinflip, returning a
bool that has a 50% chance of being true. Read moreSource§fn bound_inclusive(&mut self, max: u64) -> u64
fn bound_inclusive(&mut self, max: u64) -> u64
Source§fn f64_nonzero(&mut self) -> f64
fn f64_nonzero(&mut self) -> f64
Returns a uniformly distributed
f64 in the interval (0.0, 1.0].Source§fn f32_nonzero(&mut self) -> f32
fn f32_nonzero(&mut self) -> f32
Returns a uniformly distributed
f32 in the interval (0.0, 1.0].Source§fn f64_wide(&mut self) -> f64
fn f64_wide(&mut self) -> f64
Returns a uniformly distributed
f64 in the interval (-1.0, 1.0).Source§fn f32_wide(&mut self) -> f32
fn f32_wide(&mut self) -> f32
Returns a uniformly distributed
f32 in the interval (-1.0, 1.0).Source§fn f64_normal(&mut self) -> (f64, f64)
fn f64_normal(&mut self) -> (f64, f64)
Returns two indepedent and normally distributed
f64 values with
a mean of 0.0 and a stddev of 1.0.Source§fn f64_normal_distribution(&mut self, mean: f64, stddev: f64) -> (f64, f64)
fn f64_normal_distribution(&mut self, mean: f64, stddev: f64) -> (f64, f64)
Returns two indepedent and normally distributed
f64 values with
user-defined mean and stddev. Read moreSource§fn f64_exponential(&mut self) -> f64
fn f64_exponential(&mut self) -> f64
Returns an exponentially distributed
f64 with lambda of 1.0.Source§fn f64_exponential_lambda(&mut self, lambda: f64) -> f64
fn f64_exponential_lambda(&mut self, lambda: f64) -> f64
Source§fn choose<C>(&mut self, collection: C) -> Option<C::Item>
fn choose<C>(&mut self, collection: C) -> Option<C::Item>
Returns a randomly chosen item from the iterator of
collection. Read moreSource§fn ascii_alphabetic(&mut self) -> char
fn ascii_alphabetic(&mut self) -> char
Returns a randomly selected ASCII character from the pool of: Read more
Source§fn ascii_uppercase(&mut self) -> char
fn ascii_uppercase(&mut self) -> char
Returns a randomly selected ASCII character from the pool of: Read more
Source§fn ascii_lowercase(&mut self) -> char
fn ascii_lowercase(&mut self) -> char
Returns a randomly selected ASCII character from the pool of: Read more
Source§fn ascii_alphanumeric(&mut self) -> char
fn ascii_alphanumeric(&mut self) -> char
Returns a randomly selected ASCII character from the pool of: Read more
Source§fn ascii_digit(&mut self) -> char
fn ascii_digit(&mut self) -> char
Returns a randomly selected ASCII character from the pool of: Read more
Auto Trait Implementations§
impl Freeze for SecureRng
impl RefUnwindSafe for SecureRng
impl Send for SecureRng
impl Sync for SecureRng
impl Unpin for SecureRng
impl UnwindSafe for SecureRng
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