Today, my friend asked me a question:
Requirement: generate 0 ~ 9. The number is 10 and cannot be repeated within 10 times.
I gave his answer without thinking about it at the time:
-----------------------------------------------------
# Include <iostream>
# Include <time. h>
Using namespace STD;
Int main ()
{
Srand (time (0 ));
Int n = rand () % 10;
For (INT I = 0; I <10; ++ I)
{
Printf ("% d", (n + I) % 10 );
}
Getchar ();
Return 0;
}
-----------------------------------------------------
However, he said, "You generate 0 ~ 9. The ten numbers are always ordered. "Yes, I generate 0 ~ 9 The total number of these 10 numbers is 0 ~ 9. He turned around in this circle and asked me if I could generate 0 in random order ~ 9. These 10 numbers are not repeated for 10 times. the answer I gave him was no. because I cannot guarantee that the numbers I have generated for 10 times are different, I can only add a certain number to avoid it. If anyone can, please help! Thank you!