Struct esp32c3_hal::Rng

source ·
pub struct Rng<'d> { /* private fields */ }
Expand description

Random Number Generator

It should be noted that there are certain pre-conditions which must be met in order for the RNG to produce true random numbers. The hardware RNG produces true random numbers under any of the following conditions:

  • RF subsystem is enabled (i.e. Wi-Fi or Bluetooth are enabled).
  • An internal entropy source has been enabled by calling bootloader_random_enable() and not yet disabled by calling bootloader_random_disable().
  • While the ESP-IDF Second stage bootloader is running. This is because the default ESP-IDF bootloader implementation calls bootloader_random_enable() when the bootloader starts, and bootloader_random_disable() before executing the app.

When any of these conditions are true, samples of physical noise are continuously mixed into the internal hardware RNG state to provide entropy. If none of the above conditions are true, the output of the RNG should be considered pseudo-random only.

For more information, please refer to the ESP-IDF documentation: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/random.html

Implementations§

source§

impl<'d> Rng<'d>

source

pub fn new(rng: impl Peripheral<P = RNG> + 'd) -> Rng<'d>

Create a new random number generator instance

source

pub fn random(&mut self) -> u32

Reads currently available u32 integer from RNG

Trait Implementations§

source§

impl Read for Rng<'_>

§

type Error = Infallible

Error type
source§

fn read(&mut self, buffer: &mut [u8]) -> Result<(), <Rng<'_> as Read>::Error>

Reads enough bytes from hardware random number generator to fill buffer Read more

Auto Trait Implementations§

§

impl<'d> RefUnwindSafe for Rng<'d>

§

impl<'d> Send for Rng<'d>

§

impl<'d> Sync for Rng<'d>

§

impl<'d> Unpin for Rng<'d>

§

impl<'d> !UnwindSafe for Rng<'d>

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

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.