pub async fn raw_rand() -> Result<[u8; 32], String>Expand description
Retrieves 32 bytes of randomness from the Internet Computer management canister.
§Behavior
Calls the management canister’s raw_rand
method, which returns 32 random bytes (256 bits) of cryptographically secure randomness.
These bytes can be used as a seed for random number generators or as a unique salt.
The function performs length validation to ensure the result is exactly 32 bytes.
§Returns
Ok([u8; 32])containing the random seed bytes on success.Err(String)with an error message if the call failed or returned an unexpected length.
§Example
ⓘ
let seed = raw_rand().await?;
println!("Received 32 bytes of randomness: {:?}", seed);