The official website tells us there is " A secure, local entropy source for random number generation" . I think it means that I can make use of this feature to generate random number or even generate key pair in offchain worker. I want to know how to implement this.Is there any code snippet that I could learn?
1 Answer
For offchain workers there is the random_seed
function. This will return you a random seed that you can use to initialize a random number generator.
-
Sorry , I am a green hand and I don't have much experience. Can you tell me which crate should I import into my code?– kugoolAug 19, 2022 at 9:01
-
1You could use
ChaCha20Rng
.ChaCha20Rng::from_seed(sp_io::offchain::random_seed()).next_u32()
.– bkchrAug 19, 2022 at 11:11