How does C#’s random number generator work?

You can use Random.Next(int maxValue):

Return:
A 32-bit signed integer greater than or equal to zero, and less than
maxValue; that is, the range of return values ordinarily includes zero
but not maxValue. However, if maxValue equals zero, maxValue is
returned.

var r = new Random();
// print random integer >= 0 and  < 100
Console.WriteLine(r.Next(100));

For this case however you could use Random.Next(int minValue, int maxValue), like this:

// print random integer >= 1 and < 101
Console.WriteLine(r.Next(1, 101);)
// or perhaps (if you have this specific case)
Console.WriteLine(r.Next(100) + 1);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)