Name

Random

Synopsis

This class encapsulates a pseudorandom number (one chosen from a list of pregenerated numbers, but that is statistically random). After creating an instance of this class, use the Next(), NextDouble(), or NextBytes() method to return random information. NextDouble() returns a fraction value between 0.0 and 1.0, while Next() returns an integer between 0 and the maximum bound that you specify. NextBytes() fills a supplied array of bytes with random numbers.

When creating a Random object, you supply a seed value to the constructor, which determines the place on the list from where the random number is drawn. If you supply the same seed value to multiple Random instances, you will receive the same random number. Computers are incapable of generating truly random numbers, and Random should not be used for cryptographic algorithms. For a cryptographically strong random number generator, see the System.Security.Cryptography.RandomNumberGenerator in the .NET Framework SDK Documentation.

public class Random {
// Public Constructors
   public method Random();  
   public method Random(int Seed);  
// Public Instance Methods
   public virtual method int Next();  
   public virtual method int Next(int maxValue);  
   public virtual method int Next(int minValue, 
        int maxValue);  
   public virtual method void NextBytes(byte[] buffer);  
   public virtual method double NextDouble();  
// Protected Instance Methods
   protected virtual method double Sample();  
}

Get C# in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.