nrf/rng: expose all functionality as inherent methods.
This commit is contained in:
@ -5,9 +5,7 @@
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
|
||||
use defmt::unwrap;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::traits::rng::Rng as _;
|
||||
use embassy_nrf::interrupt;
|
||||
use embassy_nrf::rng::Rng;
|
||||
use embassy_nrf::Peripherals;
|
||||
@ -19,14 +17,14 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
|
||||
// Async API
|
||||
let mut bytes = [0; 4];
|
||||
unwrap!(rng.fill_bytes(&mut bytes).await); // nRF RNG is infallible
|
||||
rng.fill_bytes(&mut bytes).await;
|
||||
defmt::info!("Some random bytes: {:?}", bytes);
|
||||
|
||||
// Sync API with `rand`
|
||||
defmt::info!("A random number from 1 to 10: {:?}", rng.gen_range(1..=10));
|
||||
|
||||
let mut bytes = [0; 1024];
|
||||
unwrap!(rng.fill_bytes(&mut bytes).await);
|
||||
rng.fill_bytes(&mut bytes).await;
|
||||
let zero_count: u32 = bytes.iter().fold(0, |acc, val| acc + val.count_zeros());
|
||||
let one_count: u32 = bytes.iter().fold(0, |acc, val| acc + val.count_ones());
|
||||
defmt::info!(
|
||||
|
Reference in New Issue
Block a user