+ 1

How do I generate random numbers in c#? Need some help

24th May 2018, 8:24 PM
Corey Bryan
Corey Bryan - avatar
2 ответов
0
The Random class is used to create random numbers. (Pseudo-random that is of course.). Example: Random rnd = new Random(); int month = rnd.Next(1, 13); // creates a number between 1 and 12 int dice = rnd.Next(1, 7); // creates a number between 1 and 6 int card = rnd.Next(52); // creates a number between 0 and 51 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. https://stackoverflow.com/questions/2706500/how-do-i-generate-a-random-int-number-in-c
24th May 2018, 8:39 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 1
https://msdn.microsoft.com/en-us/library/system.random(v=vs.110).aspx
24th May 2018, 8:35 PM
Fata1 Err0r
Fata1 Err0r - avatar