pub struct RpoRandomCoin { /* private fields */ }
Expand description
A simplified version of the SPONGE_PRG
reseedable pseudo-random number generator algorithm
described in https://eprint.iacr.org/2011/499.pdf.
The simplification is related to the following facts:
- A call to the reseed method implies one and only one call to the permutation function. This is possible because in our case we never reseed with more than 4 field elements.
- As a result of the previous point, we don’t make use of an input buffer to accumulate seed material.
Implementations§
source§impl RpoRandomCoin
impl RpoRandomCoin
sourcepub fn new(seed: Word) -> Self
pub fn new(seed: Word) -> Self
Returns a new RpoRandomCoin initialize with the specified seed.
sourcepub fn from_parts(state: [Felt; 12], current: usize) -> Self
pub fn from_parts(state: [Felt; 12], current: usize) -> Self
Returns an RpoRandomCoin instantiated from the provided components.
§Panics
Panics if current
is smaller than 4 or greater than or equal to 12.
sourcepub fn into_parts(self) -> ([Felt; 12], usize)
pub fn into_parts(self) -> ([Felt; 12], usize)
Returns components of this random coin.
sourcepub fn fill_bytes(&mut self, dest: &mut [u8])
pub fn fill_bytes(&mut self, dest: &mut [u8])
Fills dest
with random data.
Trait Implementations§
source§impl Clone for RpoRandomCoin
impl Clone for RpoRandomCoin
source§fn clone(&self) -> RpoRandomCoin
fn clone(&self) -> RpoRandomCoin
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for RpoRandomCoin
impl Debug for RpoRandomCoin
source§impl Deserializable for RpoRandomCoin
impl Deserializable for RpoRandomCoin
source§fn read_from<R: ByteReader>(
source: &mut R,
) -> Result<Self, DeserializationError>
fn read_from<R: ByteReader>( source: &mut R, ) -> Result<Self, DeserializationError>
Reads a sequence of bytes from the provided
source
, attempts to deserialize these bytes
into Self
, and returns the result. Read moresource§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
source§impl FeltRng for RpoRandomCoin
impl FeltRng for RpoRandomCoin
source§impl PartialEq for RpoRandomCoin
impl PartialEq for RpoRandomCoin
source§impl RandomCoin for RpoRandomCoin
impl RandomCoin for RpoRandomCoin
source§type BaseField = BaseElement
type BaseField = BaseElement
Base field for random elements which can be generated by this random coin.
source§type Hasher = Rpo256
type Hasher = Rpo256
Hash function which is used by the random coin to generate random field elements.
source§fn new(seed: &[Self::BaseField]) -> Self
fn new(seed: &[Self::BaseField]) -> Self
Returns a new random coin instantiated with the provided
seed
.source§fn reseed(&mut self, data: RpoDigest)
fn reseed(&mut self, data: RpoDigest)
Reseeds the coin with the specified data by setting the new seed to hash(
seed
|| data
).source§fn check_leading_zeros(&self, value: u64) -> u32
fn check_leading_zeros(&self, value: u64) -> u32
Computes hash(
seed
|| value
) and returns the number of leading zeros in the resulting
value if it is interpreted as an integer in big-endian byte order.source§fn draw<E: FieldElement<BaseField = Felt>>(
&mut self,
) -> Result<E, RandomCoinError>
fn draw<E: FieldElement<BaseField = Felt>>( &mut self, ) -> Result<E, RandomCoinError>
Returns the next pseudo-random field element. Read more
source§impl RngCore for RpoRandomCoin
impl RngCore for RpoRandomCoin
source§fn fill_bytes(&mut self, dest: &mut [u8])
fn fill_bytes(&mut self, dest: &mut [u8])
Fill
dest
with random data. Read moresource§impl Serializable for RpoRandomCoin
impl Serializable for RpoRandomCoin
source§fn write_into<W: ByteWriter>(&self, target: &mut W)
fn write_into<W: ByteWriter>(&self, target: &mut W)
Serializes
self
into bytes and writes these bytes into the target
.source§fn get_size_hint(&self) -> usize
fn get_size_hint(&self) -> usize
Returns an estimate of how many bytes are needed to represent self. Read more
impl Copy for RpoRandomCoin
impl Eq for RpoRandomCoin
impl StructuralPartialEq for RpoRandomCoin
Auto Trait Implementations§
impl Freeze for RpoRandomCoin
impl RefUnwindSafe for RpoRandomCoin
impl Send for RpoRandomCoin
impl Sync for RpoRandomCoin
impl Unpin for RpoRandomCoin
impl UnwindSafe for RpoRandomCoin
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)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>,
Generate a random value in the given range. Read more
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>,
Sample a new value, using the given distribution. Read more
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,
Create an iterator that generates values using the given distribution. Read more
source§fn 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 moresource§fn 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