Generating Random Numbers in C#

suggest change

Syntax

Parameters

Parameter Details
Seed Value used to start the generator. If omitted, the default constructor uses the system clock.
minValue Inclusive lower bound. Next(int, int) throws if minValue is greater than maxValue.
maxValue Exclusive upper bound for Next(int) and Next(int, int). Next(0) returns 0. A negative maxValue throws ArgumentOutOfRangeException.
return value The generated int. Parameterless Next() is in the range 0 inclusive to int.MaxValue exclusive.

Remarks

Two Random instances created in the same clock tick can share that default seed and then produce the same sequence. Pass distinct seeds, or reuse one instance, when the sequences must differ. The same seed is repeatable on a given implementation of Random; the algorithm is not guaranteed to stay the same across major .NET versions.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents