Reject text: Canister ryjl3-tyaaa-aaaaa-abbba-cai trapped explicitly: Panicked at ‘could not initialize thread_rng: getrandom: this target is not supported’, /Users/xxxx/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.7.3/src/rngs/thread.rs:65:17
dependencies:
rand = “0.7.3”
getrandom = { version = “0.2.6”, features = [“js”]}
“dfx”: “0.9.3”,
I refered to previous solution, it doesn’t work. Does anyone know how to solve it?
features = [“js”] works in a JS environment; it does not work in a freestanding WASM environment. What you instead do is use the register_custom_getrandom! macro to register a CSPRNG you seeded through ic0.raw_rand. (I am curious what previous solution you refer to, that wasn’t that.)
This will return the same numbers every time. What you can do instead is seed an RNG of your choice with raw_rand. Once created and stored in a static, this RNG can be used synchronously. For example: