After noticing that the rand() function produced the same output of 41 each time, I seeded the generator using srand(time(0)). That solved the problem of the recurring outpu
This bug comes up about once a week here:
If you call srand() every time before you call rand(), then you're not getting random numbers at all, you're getting a hash function of the time. Call srand() ONCE, AND ONLY ONCE, outside the loop, preferably at the very start of your program, then call rand() as many times as needed to get values.
There's no such thing as generating "one random number". If you need random numbers over a series of program invocations, you have no choice but to generate those random numbers outside the program. One way to do that is to read from /dev/urandom (on Linux) or use CryptGenRandom (on Windows). Another option is to use hardware, or a service like random.org.
It doesn't matter how good a generator you have--if you seed every call, you're not getting random numbers, you're getting a hash function of the seed value. If your seed value changes fast enough, and the hash function is very good, that might be good enough--but it's still not using the RNG algorithm at all.