• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[C++] Prevent generating number below 20 with function rand() twice in a row

G

glapa93

Guest
I execute this script every second and I do not want the message "I must be only once in a row!" to display more than once in a row. It can be displayed multiple times but never one after another one.
C++:
    // int x = 1;
    int chance = uniform_random(1, 100);

    if (20 <= chance)
        std:cout << "I can be many times in a row!";
       // x= 0;
    }
    else
    {
       // x = 1;
        std:cout << "I must be only once in a row!";
    }
 
C++:
    //this must be stored somewhere outside of the function scope
    int x = 1;

    int chance = uniform_random(1, 100);

    if (20 <= chance || x == 1)
        std:cout << "I can be many times in a row!";
        x= 0;
    }
    else
    {
        x = 1;
        std:cout << "I must be only once in a row!";
    }
 
Back
Top