Home > Back-end >  How can get under rapid cycling srand different random Numbers?
How can get under rapid cycling srand different random Numbers?

Time:03-06

Srand ((unsigned) time (NULL));
y=4;
While (1)
{
X=rand () % 97 + 2;
C=rand () % 'z' + 'A';
}

Above is a random Numbers and random letters, but due to the fast loop and the results obtained are the same, use Sleep (1000) so that you can, if there is any way can be obtained in the rapid different random Numbers? Please give directions! Thank you very much!

CodePudding user response:

Simple, you can put the cycles as a variable with a simple algorithm is added to the random seed, for example: srand (time (0) + number + % 2 times * 1000)
  • Related