I have a question: so I know of the way to have rand() come up with a new random number every second, is there a way to have it give me a new random number, say, every millisecond?
rand() gives you a new random number every time you call it. Time has nothing to do with it.
The only way time has anything to do with it is when you seed the RNG with srand()... which you should only be doing once. The mistake you're making is probably seeding every time you generate a number, which is wrong.
1 2 3 4 5 6 7 8
int main()
{
srand( (unsigned)time(0) ); // seed ONLY ONCE
// get 2 random numbers between [0..9]
int a = rand() % 10;
int b = rand() % 10;
}
Perhaps I worded my problem wrong. So I seed rand once, but I generate random numbers in a loop, in essence getting the same number for several thousand times until rand() switches to a new number, and then spits it out for another few thousand times. I want to know how to change this, so that, in this case, rand() would switch random numbers every millisecond. The case is that I am calling rand() repeatedly.