[Solved] C++, twenty numbers not random? [closed]


You need to call rand() each time you want a random number. As you have it now you’re generating one random number, then incrementing it and printing it out 20 times so you’re going to get 20 sequential numbers.

Try something like

srand(time(NULL)); // Seeding the random number generator

for(int i=0; i<20; ++i)
{
    cout << (rand() % 100) << endl;
}

The seeding of the random number generator is important, without that you would generate the same numbers every time you ran the program.

2

solved C++, twenty numbers not random? [closed]