0

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 1

1

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.

2
  • 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?
    – kugool
    Aug 19, 2022 at 9:01
  • 1
    You could use ChaCha20Rng. ChaCha20Rng::from_seed(sp_io::offchain::random_seed()).next_u32().
    – bkchr
    Aug 19, 2022 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.