pub struct RpxRandomCoin { /* 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 RpxRandomCoin
impl RpxRandomCoin
Sourcepub fn new(seed: Word) -> Self
pub fn new(seed: Word) -> Self
Returns a new RpxRandomCoin 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 RpxRandomCoin 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.
pub fn draw_basefield(&mut self) -> Felt
Sourcepub fn draw(&mut self) -> Felt
pub fn draw(&mut self) -> Felt
Draws a random field element.
This is an alias for Self::draw_basefield.
pub fn draw_ext_field<E: ExtensionField<Felt>>(&mut self) -> E
pub fn reseed(&mut self, data: Word)
pub fn check_leading_zeros(&self, value: u64) -> u32
pub fn draw_integers( &mut self, num_values: usize, domain_size: usize, nonce: u64, ) -> Vec<usize>
Trait Implementations§
Source§impl Clone for RpxRandomCoin
impl Clone for RpxRandomCoin
Source§fn clone(&self) -> RpxRandomCoin
fn clone(&self) -> RpxRandomCoin
Returns a duplicate 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 RpxRandomCoin
impl Debug for RpxRandomCoin
Source§impl Deserializable for RpxRandomCoin
impl Deserializable for RpxRandomCoin
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 min_serialized_size() -> usize
fn min_serialized_size() -> usize
Returns the minimum serialized size for one instance of this type. Read more
Source§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
Source§fn read_from_bytes_with_budget(
bytes: &[u8],
budget: usize,
) -> Result<Self, DeserializationError>
fn read_from_bytes_with_budget( bytes: &[u8], budget: usize, ) -> Result<Self, DeserializationError>
Deserializes
Self from bytes with a byte budget limit. Read moreSource§impl FeltRng for RpxRandomCoin
impl FeltRng for RpxRandomCoin
Source§impl PartialEq for RpxRandomCoin
impl PartialEq for RpxRandomCoin
Source§impl RngCore for RpxRandomCoin
impl RngCore for RpxRandomCoin
Source§impl Serializable for RpxRandomCoin
impl Serializable for RpxRandomCoin
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 RpxRandomCoin
impl Eq for RpxRandomCoin
impl StructuralPartialEq for RpxRandomCoin
Auto Trait Implementations§
impl Freeze for RpxRandomCoin
impl RefUnwindSafe for RpxRandomCoin
impl Send for RpxRandomCoin
impl Sync for RpxRandomCoin
impl Unpin for RpxRandomCoin
impl UnwindSafe for RpxRandomCoin
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§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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R> Rng for R
impl<R> Rng for R
Source§fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
Return a random value via the
StandardUniform distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
Source§fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn random_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 random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
Return a bool with a probability
p of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
Return a bool with a probability of
numerator/denominator of being
true. Read moreSource§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) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
Create an iterator that generates values using the given distribution. Read more
Source§fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
👎Deprecated since 0.9.0: Renamed to
random to avoid conflict with the new gen keyword in Rust 2024.Alias for
Rng::random.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>,
👎Deprecated since 0.9.0: Renamed to
random_rangeAlias for
Rng::random_range.Source§impl<R> TryRngCore for R
impl<R> TryRngCore for R
Source§type Error = Infallible
type Error = Infallible
The type returned in the event of a RNG error.
Source§fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
Return the next random
u32.Source§fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
Return the next random
u64.Source§fn try_fill_bytes(
&mut self,
dst: &mut [u8],
) -> Result<(), <R as TryRngCore>::Error>
fn try_fill_bytes( &mut self, dst: &mut [u8], ) -> Result<(), <R as TryRngCore>::Error>
Fill
dest entirely with random data.Source§fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
Wrap RNG with the
UnwrapMut wrapper.Source§fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
Convert an
RngCore to a RngReadAdapter.