esp-hal/examples/src/bin/rng.rs
Dániel Buga 99bf346898
Remove the need to manually pass clocks around (#1999)
* Clean up passing clocks to drivers

* Update changelog

* Initialise Clocks in a critical section

* Fix calling now() before init

* Fix doc

* Fix esp-wifi migration guide

* Add safety comment

* Update tests
2024-09-04 14:13:51 +00:00

27 lines
622 B
Rust

//! Demonstrates the use of the hardware Random Number Generator (RNG)
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
#![no_std]
#![no_main]
use esp_backtrace as _;
use esp_hal::{prelude::*, rng::Rng};
use esp_println::println;
#[entry]
fn main() -> ! {
let peripherals = esp_hal::init(esp_hal::Config::default());
let mut rng = Rng::new(peripherals.RNG);
// Generate a random word (u32):
println!("Random u32: {}", rng.random());
// Fill a buffer with random bytes:
let mut buf = [0u8; 16];
rng.read(&mut buf);
println!("Random bytes: {:?}", buf);
loop {}
}