This question already has an answer here:

I am using sha3 to create 3 unique id in a same function. But results are same for all of them because it is using timestamp like this "uint256 random = uint256(sha3(block.timestamp)) +1;".

So, I want to know how to create random or unique id which will be not dependent on timestamp?

marked as duplicate by Richard Horrocks, Crema, Malone, Ismael, gisdev_p Nov 25 '17 at 9:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Randomness can't be done in Solidity. If you aren't worried about someone gaming this, then you can sha256 the timestamp, then hash that hash to get another hash, then hash that hash to get another, and so on.

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