'How to achieve secure randomness in smart contract development?
I have a problem with the development of my gambling game. I am trying to get a random number everytime but I don't think I am going the right way. Generating randomness is one of the key challenges in smart contract development. How can I successfully achieve this?
Solution 1:[1]
check this out. Keep in mind that using this isn't free.
Solution 2:[2]
You can generate random number from using the date
function random() view public returns (uint)
{
uint answer = block.timestamp% 10 ;
return answer;
}
This will return every time random number between 0 and 9 depending on sec but if you dont want to get it always by time you can add some global variables that change after every funtion run and chage to result so you make it more random
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Niccolò Fant |
| Solution 2 | Mohamad Al Zohbie |
