Struct snarkvm_console_network::prelude::TestRng
source · pub struct TestRng(_);
Expand description
A fast RNG used solely for testing and benchmarking, not for any real world purposes.
Implementations
sourceimpl TestRng
impl TestRng
pub fn fixed(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
sourceimpl RngCore for TestRng
impl RngCore for TestRng
sourcefn 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 RefUnwindSafe for TestRng
impl Send for TestRng
impl Sync for TestRng
impl Unpin for TestRng
impl UnwindSafe for TestRng
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T> CryptoRngCore for Twhere
T: CryptoRng + RngCore,
impl<T> CryptoRngCore for Twhere
T: CryptoRng + RngCore,
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<R> Rng for Rwhere
R: RngCore + ?Sized,
impl<R> Rng for Rwhere
R: RngCore + ?Sized,
sourcefn gen<T>(&mut self) -> Twhere
Standard: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
Standard: Distribution<T>,
sourcefn 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>,
sourcefn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
sourcefn 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,
sourcefn gen_bool(&mut self, p: f64) -> bool
fn gen_bool(&mut self, p: f64) -> bool
p
of being true. Read moresourcefn 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