Represents a pseudo-random number generator, a device that produces a sequence of numbers that meet certain statistical requirements for randomness.
For a list of all members of this type, see Random Members.
System.Object
System.Random
[Visual Basic] <Serializable> Public Class Random [C#] [Serializable] public class Random [C++] [Serializable] public __gc class Random [JScript] public Serializable class Random
Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.
Pseudo-random numbers are chosen with equal probability from a finite set of numbers. The chosen numbers are not completely random because a definite mathematical algorithm is used to select them, but they are sufficiently random for practical purposes.
The random number generation starts from a seed value. If the same seed is used repeatedly, the same series of numbers is generated. One way to produce different sequences is to make the seed value time-dependent, thereby producing a different series with each new instance of Random.
To improve performance, create one Random to generate many random numbers over time, instead of repeatedly creating a new Random to generate one random number.
To generate a cryptographically secure random number suitable for creating a random password, for example, use a class derived from System.Security.Cryptography.RandomNumberGenerator such as System.Security.Cryptography.RNGCryptoServiceProvider.
Namespace: System
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework - Windows CE .NET
Assembly: Mscorlib (in Mscorlib.dll)