pub async fn get_random_seed() -> Option<StdRng>Expand description
Initializes a StdRng using 32 bytes of randomness retrieved from the IC management canister.
§Behavior
This function internally calls raw_rand() to obtain 32 bytes of randomness
from the management canister and uses them as a seed to create a deterministic
random number generator (StdRng).
If randomness cannot be retrieved (e.g., due to a call failure), the function
returns None instead of blocking initialization. This allows the caller to
proceed with limited functionality.
§Returns
Some(StdRng)if randomness was successfully fetched.Noneif the management canister call failed.
§Example
ⓘ
if let Some(mut rng) = get_random_seed().await {
let value: u64 = rng.gen();
println!("Random value: {}", value);
}