Is this because the loop runs so fast that time(0) in srand((unsigned)time(0)) doesn't change?
Yes
If so, how can I work around that?
You should only be calling srand() once when the program starts. You should not be calling it every time you generate a random number. Doing so all but completely destroys the random number generation.