How do I generate a random int number in C#?
How do I generate a random int number in C
De openkb
Sommaire |
Questions
Answers
https://msdn.microsoft.com/en-us/library/system.random%28v=vs.110%29.aspx https://msdn.microsoft.com/en-us/library/system.random%28v=vs.110%29.aspx
Example:
Random rnd = new Random(); int month = rnd.Next(1, 13); // 1 <= month < 13 int dice = rnd.Next(1, 7); // 1 <= dice < 7 int card = rnd.Next(52); // 0 <= card < 52
If you are going to create more than one random number, you should keep the Random instance and reuse it. If you create new instances too close in time, they will produce the same series of random numbers as the random generator is seeded from the system clock.
Source
License : cc by-sa 3.0
http://stackoverflow.com/questions/2706500/how-do-i-generate-a-random-int-number-in-c