O'Reilly logo

C# in a Nutshell by Peter Drayton, Ted Neward, Ben Albahari

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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();  
}

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required