1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Random number between 0 and 1 - quick little question

Discussion in 'Finance' started by lemme, Oct 8, 2018.

  1. lemme

    lemme Guest

    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?

    Login To add answer/comment
     

Share This Page