pub struct FastRandomContext {
    pub requires_seed: bool,
    pub rng: ChaCha20,
    pub bytebuf: [u8; 64],
    pub bytebuf_size: i32,
    pub bitbuf: u64,
    pub bitbuf_size: i32,
}
Expand description

| Fast randomness source. This is seeded | once with secure random data, but is | completely deterministic and does | not gather more entropy after that. | | This class is not thread-safe. |

Fields§

§requires_seed: bool§rng: ChaCha20§bytebuf: [u8; 64]§bytebuf_size: i32§bitbuf: u64§bitbuf_size: i32

Implementations§

source§

impl FastRandomContext

source

pub fn new(deterministic: bool) -> Self

source

pub fn fill_byte_buffer(&mut self)

source

pub fn fill_bit_buffer(&mut self)

source

pub fn rand64(&mut self) -> u64

| Generate a random 64-bit integer. |

source

pub fn randbits(&mut self, bits: i32) -> u64

| Generate a random (bits)-bit integer. |

source

pub fn rand32(&mut self) -> u32

| Generate a random 32-bit integer. |

source

pub fn randbool(&mut self) -> bool

| Generate a random boolean. |

source

pub fn min() -> u64

source

pub fn max() -> u64

source

pub fn invoke(&mut self) -> u64

source

pub fn random_seed(&mut self)

source

pub fn rand256(&mut self) -> u256

| generate a random uint256. |

source

pub fn randbytes(&mut self, len: usize) -> Vec<u8>

| Generate random bytes. |

Trait Implementations§

source§

impl Default for FastRandomContext

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl From<&mut FastRandomContext> for FastRandomContext

source§

fn from(other: &mut FastRandomContext) -> Self

| Move a FastRandomContext. If the original | one is used again, it will be reseeded. |

source§

impl From<&u256> for FastRandomContext

source§

fn from(seed: &u256) -> Self

| Initialize with explicit seed (only | for testing) |

source§

impl RandRange for FastRandomContext

source§

fn randrange(&mut self, range: u64) -> u64

| Generate a random integer in the range | [0..range). | | Precondition: range > 0. |

source§

impl RngCore for FastRandomContext

source§

fn next_u32(&mut self) -> u32

Return the next random u32. Read more
source§

fn next_u64(&mut self) -> u64

Return the next random u64. Read more
source§

fn fill_bytes(&mut self, dest: &mut [u8])

Fill dest with random data. Read more
source§

fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error>

Fill dest entirely with random data. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T, U> CastInto<U> for Twhere U: CastFrom<T>,

§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<R> Rng for Rwhere R: RngCore + ?Sized,

source§

fn gen<T>(&mut self) -> Twhere Standard: Distribution<T>,

Return a random value supporting the Standard distribution. Read more
source§

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>,

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,

Create an iterator that generates values using the given distribution. Read more
source§

fn fill<T>(&mut self, dest: &mut T)where T: Fill + ?Sized,

Fill any type implementing Fill with random data Read more
source§

fn try_fill<T>(&mut self, dest: &mut T) -> Result<(), Error>where T: Fill + ?Sized,

Fill any type implementing Fill with random data Read more
source§

fn gen_bool(&mut self, p: f64) -> bool

Return a bool with a probability p of being true. Read more
source§

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
§

impl<T> StaticUpcast<T> for T

§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V