Struct tor_llcrypto::util::rand_compat::RngWrapper
source · [−]pub struct RngWrapper<T>(_);
Expand description
A new-style Rng, wrapped for backward compatibility.
This object implements both the current (0.6.2) version of RngCore
,
as well as the version from 0.5.1 that the dalek-crypto functions expect.
To get an RngWrapper, use the RngCompatExt
extension trait:
use tor_llcrypto::util::rand_compat::RngCompatExt;
let mut wrapped_rng = rand::thread_rng().rng_compat();
Trait Implementations
sourceimpl<T: RngCore> From<T> for RngWrapper<T>
impl<T: RngCore> From<T> for RngWrapper<T>
sourcefn from(rng: T) -> RngWrapper<T>
fn from(rng: T) -> RngWrapper<T>
Converts to this type from the input type.
sourceimpl<T: RngCore> RngCore for RngWrapper<T>
impl<T: RngCore> RngCore for RngWrapper<T>
sourceimpl<T: RngCore> RngCore for RngWrapper<T>
impl<T: RngCore> RngCore for RngWrapper<T>
impl<T: CryptoRng> CryptoRng for RngWrapper<T>
impl<T: CryptoRng> CryptoRng for RngWrapper<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for RngWrapper<T> where
T: RefUnwindSafe,
impl<T> Send for RngWrapper<T> where
T: Send,
impl<T> Sync for RngWrapper<T> where
T: Sync,
impl<T> Unpin for RngWrapper<T> where
T: Unpin,
impl<T> UnwindSafe for RngWrapper<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<R> RandBigInt for R where
R: Rng + ?Sized,
impl<R> RandBigInt for R where
R: Rng + ?Sized,
sourcefn gen_biguint(&mut self, bit_size: usize) -> BigUint
fn gen_biguint(&mut self, bit_size: usize) -> BigUint
Generate a random BigUint
of the given bit size.
sourcefn gen_bigint(&mut self, bit_size: usize) -> BigInt
fn gen_bigint(&mut self, bit_size: usize) -> BigInt
Generate a random BigInt of the given bit size.
sourcefn gen_biguint_below(&mut self, bound: &BigUint) -> BigUint
fn gen_biguint_below(&mut self, bound: &BigUint) -> BigUint
Generate a random BigUint
less than the given bound. Fails
when the bound is zero. Read more
sourceimpl<R> Rng for R where
R: RngCore + ?Sized,
impl<R> Rng for R where
R: RngCore + ?Sized,
sourcefn gen<T>(&mut self) -> T where
Standard: Distribution<T>,
fn gen<T>(&mut self) -> T where
Standard: Distribution<T>,
sourcefn gen_range<T, B1, B2>(&mut self, low: B1, high: B2) -> T where
T: SampleUniform,
B1: SampleBorrow<T>,
B2: SampleBorrow<T>,
fn gen_range<T, B1, B2>(&mut self, low: B1, high: B2) -> T where
T: SampleUniform,
B1: SampleBorrow<T>,
B2: SampleBorrow<T>,
Generate a random value in the range [low
, high
), i.e. inclusive of
low
and exclusive of high
. Read more
sourcefn sample<T, D>(&mut self, distr: D) -> T where
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> T where
D: Distribution<T>,
Sample a new value, using the given distribution. Read more
sourcefn sample_iter<T, D>(self, distr: D) -> DistIter<D, Self, T> where
D: Distribution<T>,
fn sample_iter<T, D>(self, distr: D) -> DistIter<D, Self, T> where
D: Distribution<T>,
Create an iterator that generates values using the given distribution. Read more
sourcefn fill<T>(&mut self, dest: &mut T) where
T: AsByteSliceMut + ?Sized,
fn fill<T>(&mut self, dest: &mut T) where
T: AsByteSliceMut + ?Sized,
Fill dest
entirely with random bytes (uniform value distribution),
where dest
is any type supporting AsByteSliceMut
, namely slices
and arrays over primitive integer types (i8
, i16
, u32
, etc.). Read more
sourcefn try_fill<T>(&mut self, dest: &mut T) -> Result<(), Error> where
T: AsByteSliceMut + ?Sized,
fn try_fill<T>(&mut self, dest: &mut T) -> Result<(), Error> where
T: AsByteSliceMut + ?Sized,
Fill dest
entirely with random bytes (uniform value distribution),
where dest
is any type supporting AsByteSliceMut
, namely slices
and arrays over primitive integer types (i8
, i16
, u32
, etc.). Read more
sourcefn gen_bool(&mut self, p: f64) -> bool
fn gen_bool(&mut self, p: f64) -> bool
Return a bool with a probability p
of being true. Read more
sourcefn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool
Return a bool with a probability of 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
sourceimpl<R> Rng for R where
R: RngCore + ?Sized,
impl<R> Rng for R where
R: RngCore + ?Sized,
sourcefn gen<T>(&mut self) -> T where
Standard: Distribution<T>,
fn gen<T>(&mut self) -> T where
Standard: Distribution<T>,
sourcefn gen_range<T, R>(&mut self, range: R) -> T where
T: SampleUniform,
R: SampleRange<T>,
fn gen_range<T, R>(&mut self, range: R) -> T where
T: SampleUniform,
R: SampleRange<T>,
Generate a random value in the given range. Read more
sourcefn sample<T, D>(&mut self, distr: D) -> T where
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> T where
D: Distribution<T>,
Sample a new value, using the given distribution. Read more
sourcefn sample_iter<T, D>(self, distr: D) -> DistIter<D, Self, T> where
D: Distribution<T>,
fn sample_iter<T, D>(self, distr: D) -> DistIter<D, Self, T> where
D: Distribution<T>,
Create an iterator that generates values using the given distribution. Read more
sourcefn gen_bool(&mut self, p: f64) -> bool
fn gen_bool(&mut self, p: f64) -> bool
Return a bool with a probability p
of being true. Read more
sourcefn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool
Return a bool with a probability of 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
sourceimpl<T> RngCompatExt for T where
T: RngCore,
impl<T> RngCompatExt for T where
T: RngCore,
type Wrapper = RngWrapper<T>
type Wrapper = RngWrapper<T>
Wrapper type returned by this trait.
sourcefn rng_compat(self) -> RngWrapper<T>
fn rng_compat(self) -> RngWrapper<T>
Return a version of this Rng that can be used with older versions of the rand_core and rand libraries, as well as the current version. Read more