When running the following code block, I need the loop to produce eight different results, but I'm only getting the same result eight times over.
1 2 3 4 5 6 7 8 9 10
unsignedint seed;
cout << "Enter a seed for random number generation: ";
cin >> seed;
srand(seed);
randValue = (1 + ((rand() + time(0)) % 5));
for (int i = 0; i < 8; i++) {
cout << randValue << endl;
}
If I insert the randValue's formula in the loop, I (of course) get eight different answers. How can I adjust it to where randValue actually produces a different answer when called?
I've made this mistake before.
What happens is although randValue is random initially, the value of that variable doesn't change through each iteration of the loop. try: