pub struct RandomCoin { /* 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 RandomCoin
impl RandomCoin
Sourcepub fn new(seed: Word) -> Self
pub fn new(seed: Word) -> Self
Returns a new RandomCoin initialized 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 a RandomCoin instantiated from the provided components.
§Panics
Panics if current is outside of the rate range.
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.
Sourcepub fn draw_basefield(&mut self) -> Felt
pub fn draw_basefield(&mut self) -> Felt
Draws a random base field element from the random coin.
This method applies the Poseidon2 permutation when the rate portion of the state is exhausted, then returns the next element from the rate portion.
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.
Sourcepub fn draw_ext_field<E: ExtensionField<Felt>>(&mut self) -> E
pub fn draw_ext_field<E: ExtensionField<Felt>>(&mut self) -> E
Draws a random extension field element.
The extension field element is constructed by drawing E::DIMENSION base field elements
and interpreting them as basis coefficients.
Trait Implementations§
Source§impl Clone for RandomCoin
impl Clone for RandomCoin
Source§fn clone(&self) -> RandomCoin
fn clone(&self) -> RandomCoin
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RandomCoin
impl Debug for RandomCoin
Source§impl Deserializable for RandomCoin
impl Deserializable for RandomCoin
Source§fn read_from<R: ByteReader>(
source: &mut R,
) -> Result<Self, DeserializationError>
fn read_from<R: ByteReader>( source: &mut R, ) -> Result<Self, DeserializationError>
source, attempts to deserialize these bytes
into Self, and returns the result. Read moreSource§fn min_serialized_size() -> usize
fn min_serialized_size() -> usize
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>
Self from bytes with a byte budget limit. Read moreSource§impl FeltRng for RandomCoin
impl FeltRng for RandomCoin
Source§impl PartialEq for RandomCoin
impl PartialEq for RandomCoin
Source§impl RngCore for RandomCoin
impl RngCore for RandomCoin
Source§impl Serializable for RandomCoin
impl Serializable for RandomCoin
Source§fn write_into<W: ByteWriter>(&self, target: &mut W)
fn write_into<W: ByteWriter>(&self, target: &mut W)
self into bytes and writes these bytes into the target.Source§fn get_size_hint(&self) -> usize
fn get_size_hint(&self) -> usize
impl Copy for RandomCoin
impl Eq for RandomCoin
impl StructuralPartialEq for RandomCoin
Auto Trait Implementations§
impl Freeze for RandomCoin
impl RefUnwindSafe for RandomCoin
impl Send for RandomCoin
impl Sync for RandomCoin
impl Unpin for RandomCoin
impl UnsafeUnpin for RandomCoin
impl UnwindSafe for RandomCoin
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> 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>
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 random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
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>,
Source§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
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
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>,
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,
Source§fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
Renamed to random to avoid conflict with the new gen keyword in Rust 2024.
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>,
Renamed to random_range
Rng::random_range.Source§impl<R> TryRngCore for R
impl<R> TryRngCore for R
Source§type Error = Infallible
type Error = Infallible
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>
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>
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>
dest entirely with random data.Source§fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
UnwrapMut wrapper.Source§fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
RngCore to a RngReadAdapter.