How to get random numbers using c#.net
By aLpE
Here’s a simple function that generates random numbers using C#.net.
Random random= newRandom();
protected int GetRandomInt(intmin, int max)
{return random.Next(min,max);
}
int
myInt = GetRandomInt(10, 100); //gives in random integer between 10 & 100
First, the Random type is a class in the base class library, and is available in programs that include the System namespace.
Random class actually generates pseudo random numbers,with the “seed” for the randomizer being the system time. If your loop is sufficiently fast, the system clock time will not appear different to the randomizer and each new instance of the Random class would start off with the same seed and give you the same pseudo random number.
Comments
No comments yet.