I am writing smart contract and stucked on this line :

int p = 0;
p = (rand() % 997);

This is giving error

error: use of undeclared identifier 'rand'

I do search and got some reference links but not getting expected answers. Some old answers reference links are also not valid now. Can somebody please help to generate random numbers in a smart contract?

  • you can't do that, for smart contract can't support random method
    – Jimmy Guo
    Dec 14 '20 at 6:04
  • Okay, I want to implement the Shamir Secret Sharing Algorithm in a smart contract, I was needed random numbers for this. Can you suggest some alternative for this?
    – Varsh
    Dec 14 '20 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.