I know that the topic of random number has been discussed tremendous amount of times already but I have one small question.
I need to get a pseudo random number (not ungamealbe), as simply as possible. The problem is that I need the number to be either 1 or 0 and I want the value to be able to be odd or even in every loop iteration.
If I use something like:
while(x < 10) {
uint randomNumberBetween0And1 = uint(keccak256(abi.encodePacked(block.difficulty, now))) % 2;
x++;
}
this value will be either 10 times 0 (0 in each iteration because random number is even) or 10 x 1 (because random number will be odd every single time). How can I make the random differ between the iterations?
x
variable as a nonce (as well as a loop counter), and incorporate it into what you pass to thekeccak()
call.