MCPcopy Create free account
hub / github.com/dfinity/orbit / initialize_rng

Function initialize_rng

libs/orbit-essentials/src/utils/random.rs:46–63  ·  view source on GitHub ↗

Initializes the random number generator if it has not been initialized yet. This function is async because it may need to call into the management canister to get a seed with `raw_rand``.

()

Source from the content-addressed store, hash-verified

44///
45/// This function is async because it may need to call into the management canister to get a seed with `raw_rand``.
46pub async fn initialize_rng() -> Result<(), String> {
47 ic_cdk::print("started to initialize rng");
48
49 let (created_seed,) = management_canister::main::raw_rand()
50 .await
51 .map_err(|e| e.1)?;
52
53 let seed = created_seed
54 .try_into()
55 .map_err(|_| "raw_rand not 32 bytes".to_string())?;
56
57 initialize_rng_from_seed(seed);
58
59 RAW_RAND_SUCCESSFUL.with(|b| *b.borrow_mut() = true);
60
61 ic_cdk::print("rng succesfully initialized");
62 Ok(())
63}
64
65/// Initializes the random number generator with the given seed.
66pub fn initialize_rng_from_seed(seed: [u8; 32]) {

Callers 2

initialize_rng_timerMethod · 0.85
initialize_rng_timerFunction · 0.85

Calls 3

printFunction · 0.85
raw_randFunction · 0.85
initialize_rng_from_seedFunction · 0.85

Tested by

no test coverage detected