Skip to Main Content
C# in a Nutshell
book

C# in a Nutshell

by Ben Albahari, Ted Neward, Peter Drayton
March 2002
Intermediate to advanced content levelIntermediate to advanced
864 pages
31h 8m
English
O'Reilly Media, Inc.
Content preview from C# in a Nutshell

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();  
}
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# 8.0 in a Nutshell

C# 8.0 in a Nutshell

Joseph Albahari, Eric Johannsen
C# 10 in a Nutshell

C# 10 in a Nutshell

Joseph Albahari
C# in a Nutshell, Second Edition

C# in a Nutshell, Second Edition

Peter Drayton, Ben Albahari, Ted Neward
Code like a Pro in C#

Code like a Pro in C#

Jort Rodenburg

Publisher Resources

ISBN: 0596001819Catalog PageErrata