Stats

127 Contributors: 6
2017-05-22
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook

Generating Random Numbers in C#

Download c# eBook

Syntax

  • Random()

  • Random(int Seed)

  • int Next()

  • int Next(int maxValue)

  • int Next(int minValue, int maxValue)

Parameters

ParametersDetails
SeedA value for generating random numbers. If not set, the default value is determined by the current system time.
minValueGenerated numbers won't be smaller than this value. If not set, the default value is 0.
maxValueGenerated numbers will be smaller than this value. If not set, the default value is Int32.MaxValue.
return valueReturns a number with random value.

Remarks

The random seed generated by the system isn't the same in every different run.

Seeds generated in the same time might be the same.

Related Examples