pub struct TestRng(/* private fields */);
Expand description
A fast RNG used solely for testing and benchmarking, not for any real world purposes.
Implementations§
Source§impl TestRng
impl TestRng
pub fn fixed(seed: u64) -> TestRng
pub fn from_seed(seed: u64) -> TestRng
Sourcepub fn next_string(&mut self, max_bytes: u32, is_fixed_size: bool) -> String
pub fn next_string(&mut self, max_bytes: u32, is_fixed_size: bool) -> String
Returns a randomly-sampled String
, given the maximum size in bytes and an RNG.
Some of the snarkVM internal tests involve the random generation of strings, which are parsed and tested against the original ones. However, since the string parser rejects certain characters, if those characters are randomly generated, the tests fail.
To prevent these failures, as we randomly generate the characters, we ensure that they are not among the ones rejected by the parser; if they are, we adjust them to be allowed characters.
Note that the randomness of the characters is strictly for testing purposes; also note that the disallowed characters are a small fraction of the total set of characters, and thus the adjustments rarely occur.
Trait Implementations§
Source§impl RngCore for TestRng
impl RngCore for TestRng
Source§fn fill_bytes(&mut self, dest: &mut [u8])
fn fill_bytes(&mut self, dest: &mut [u8])
dest
with random data. Read moreimpl CryptoRng for TestRng
Auto Trait Implementations§
impl Freeze for TestRng
impl RefUnwindSafe for TestRng
impl Send for TestRng
impl Sync for TestRng
impl Unpin for TestRng
impl UnwindSafe for TestRng
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
Source§impl<T> CryptoRngCore for T
impl<T> CryptoRngCore for T
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> ⓘ
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> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R> Rng for R
impl<R> Rng for R
Source§fn gen<T>(&mut self) -> Twhere
Standard: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
Standard: Distribution<T>,
Source§fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Source§fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
Source§fn sample_iter<T, D>(self, distr: D) -> DistIter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> DistIter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
Source§fn gen_bool(&mut self, p: f64) -> bool
fn gen_bool(&mut self, p: f64) -> bool
p
of being true. Read moreSource§fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool
numerator/denominator
of being
true. I.e. gen_ratio(2, 3)
has chance of 2 in 3, or about 67%, of
returning true. If numerator == denominator
, then the returned value
is guaranteed to be true
. If numerator == 0
, then the returned
value is guaranteed to be false
. Read more