pub struct DeterministicRng { /* private fields */ }Expand description
Seeded deterministic RNG that produces the same sequence for a given seed.
§Examples
use weavegraph::utils::deterministic_rng::DeterministicRng;
let mut rng = DeterministicRng::new(42);
let value1 = rng.random_u64();
let mut rng2 = DeterministicRng::new(42);
assert_eq!(value1, rng2.random_u64());Implementations§
Source§impl DeterministicRng
impl DeterministicRng
Sourcepub fn random_u64(&mut self) -> u64
pub fn random_u64(&mut self) -> u64
Draw a random u64.
Sourcepub fn random_u32(&mut self) -> u32
pub fn random_u32(&mut self) -> u32
Draw a random u32.
Sourcepub fn random_bool(&mut self) -> bool
pub fn random_bool(&mut self) -> bool
Draw a random bool.
Sourcepub fn random_f64(&mut self) -> f64
pub fn random_f64(&mut self) -> f64
Draw a random f64 in [0.0, 1.0).
Sourcepub fn random_range_u32(&mut self, min: u32, max: u32) -> u32
pub fn random_range_u32(&mut self, min: u32, max: u32) -> u32
Draw a u32 in [min, max). Returns min when min >= max.
Sourcepub fn random_string(&mut self, len: usize) -> String
pub fn random_string(&mut self, len: usize) -> String
Generate a random lowercase-ASCII string of length len.
§Examples
use weavegraph::utils::deterministic_rng::DeterministicRng;
let mut rng = DeterministicRng::new(42);
let s = rng.random_string(8);
assert_eq!(s.len(), 8);
assert!(s.chars().all(|c| c.is_ascii_lowercase()));Sourcepub fn random_alphanumeric(&mut self, len: usize) -> String
pub fn random_alphanumeric(&mut self, len: usize) -> String
Generate a random alphanumeric string of length len.
§Examples
use weavegraph::utils::deterministic_rng::DeterministicRng;
let mut rng = DeterministicRng::new(42);
let id = rng.random_alphanumeric(12);
assert_eq!(id.len(), 12);
assert!(id.chars().all(|c| c.is_ascii_alphanumeric()));Trait Implementations§
Auto Trait Implementations§
impl Freeze for DeterministicRng
impl RefUnwindSafe for DeterministicRng
impl Send for DeterministicRng
impl Sync for DeterministicRng
impl Unpin for DeterministicRng
impl UnsafeUnpin for DeterministicRng
impl UnwindSafe for DeterministicRng
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more