I have a simple integer vector, with only 4 values. I want to loop through the vector, assigning either 0 or 1 to each value. I want it to be random to the point that its different every time.
I thought the following would suffice:
for (int i = 0; i < (int)numberVect.size(); i++)
{
numberVect[i] = rand() % 2;
}
However, what I found was that every time I would close and re-open the program, the exact same values would be assigned.
So the first time through it would be 1,0,0,0, then if I ran the loop again without closing the program it would be 0,1,0,1. which seems perfect.
HOWEVER, after closing the program and restarting it up again, I would find the first sequence would again be 1,0,0,0 and the second would again be 0,1,0,1.
Also I have a second question in relation to this problem:
Can you suggest a way to make sure that AT LEAST one of the values in the vector is a 1? while still allowing the random generation to work seamlessly?
Thanks a lot and I hope you guys can help :D