C# Class PeterO.RandomGenerator

A class that adapts a random byte generator to generate random numbers in a variety of statistical distributions.

The method descriptions in this class assume the underlying random byte generator generates uniformly distributed numbers that are independent of each other.

Thread safety: The methods in this class are safe for concurrent use by multiple threads, as long as the underlying random byte generator is as well.

Afficher le fichier Open project: peteroupc/CBOR Class Usage Examples

Méthodes publiques

Méthode Description
Bernoulli ( ) : bool

Returns either true or false at a 50% chance each.

Bernoulli ( double p ) : bool

Returns either true or false, depending on the given probability.

Binomial ( int trials ) : int

Conceptually, generates either 1 or 0 the given number of times, where either number is equally likely, and counts the number of 1's generated.

Binomial ( int trials, double p ) : int

Conceptually, generates either 1 or 0 the given number of times, where a 1 is generated at the given probability, and counts the number of 1's generated.

ChiSquared ( int df ) : double

Generates a random number that is the sum of the squares of "df" normally-distributed random numbers with a mean of 0 and a standard deviation of 1.

Exponential ( ) : double

Not documented yet.

Gamma ( double a ) : double

Not documented yet.

Gamma ( double a, double b ) : double

Not documented yet.

Geometric ( ) : int

Conceptually, generates either 1 or 0 until a 1 is generated, and counts the number of 0's generated. Either number has an equal probability of being generated.

Geometric ( double p ) : int

Conceptually, generates either 1 or 0 until a 1 is generated, and counts the number of 0's generated. A 1 is generated at the given probability.

Hypergeometric ( int trials, int ones, int count ) : int

Conceptually, given a set of tokens, some of which are labeled 1 and the others labeled 0, draws "trials" tokens at random without replacement and then counts the number of 1's drawn.

LogNormal ( double mean, double sd ) : double

Generates a logarithmic normally-distributed number with the given mean and standard deviation.

NegativeBinomial ( int trials ) : int

Conceptually, generates either 1 or 0 the given number of times until the given number of 1's are generated, and counts the number of 0's generated. Either number has an equal probability of being generated.

NegativeBinomial ( int trials, double p ) : int

Conceptually, generates either 1 or 0 until the given number of 1's are generated, and counts the number of 0's generated. A 1 is generated at the given probability.

Normal ( ) : double

Generates a normally-distributed number with mean 0 and standard deviation 1.

Normal ( double mean, double sd ) : double

Generates a normally-distributed number with the given mean and standard deviation.

Poisson ( double mean ) : int

Generates a random integer such that the average of random numbers approaches the given mean number when this method is called repeatedly with the same mean.

RandomGenerator ( ) : System

Initializes a new instance of the RandomGenerator class.

RandomGenerator ( IRandomGen valueIrg ) : System

Initializes a new instance of the RandomGenerator class.

Uniform ( ) : double

Returns a uniformly-distributed 64-bit floating-point number from 0 and up, but less than 1.

Uniform ( double max ) : double

Returns a uniformly-distributed 64-bit floating-point number from 0 and up, but less than the given number.

Uniform ( double min, double max ) : double

Not documented yet.

UniformInt ( int maxExclusive ) : int

Generates a random 32-bit signed integer 0 or greater and less than the given number.

UniformInt ( int minInclusive, int maxExclusive ) : int

Generates a random 32-bit signed integer within a given range.

UniformLong ( long maxExclusive ) : long

Generates a random 32-bit signed integer 0 or greater and less than the given number.

UniformLong ( long minInclusive, long maxExclusive ) : long

Generates a random 64-bit signed integer within a given range.

UniformSingle ( ) : double

Returns a uniformly-distributed 32-bit floating-point number from 0 and up, but less than 1.

Private Methods

Méthode Description
NonZeroUniform ( ) : double

Method Details

Bernoulli() public méthode

Returns either true or false at a 50% chance each.
public Bernoulli ( ) : bool
Résultat bool

Bernoulli() public méthode

Returns either true or false, depending on the given probability.
public Bernoulli ( double p ) : bool
p double A probability from 0 through 1. 0 means always /// false, and 1 means always true.
Résultat bool

Binomial() public méthode

Conceptually, generates either 1 or 0 the given number of times, where either number is equally likely, and counts the number of 1's generated.
public Binomial ( int trials ) : int
trials int The number of times to generate a random /// number, conceptually.
Résultat int

Binomial() public méthode

Conceptually, generates either 1 or 0 the given number of times, where a 1 is generated at the given probability, and counts the number of 1's generated.
public Binomial ( int trials, double p ) : int
trials int The number of times to generate a random /// number, conceptually.
p double The probability for each trial to succeed, from 0 /// (never) to 1 (always).
Résultat int

ChiSquared() public méthode

Generates a random number that is the sum of the squares of "df" normally-distributed random numbers with a mean of 0 and a standard deviation of 1.
public ChiSquared ( int df ) : double
df int Degrees of freedom (the number of independently /// chosen normally-distributed numbers).
Résultat double

Exponential() public méthode

Not documented yet.
public Exponential ( ) : double
Résultat double

Gamma() public méthode

Not documented yet.
public Gamma ( double a ) : double
a double Another 64-bit floating-point number.
Résultat double

Gamma() public méthode

Not documented yet.
public Gamma ( double a, double b ) : double
a double Another 64-bit floating-point number.
b double A 64-bit floating-point number. (3).
Résultat double

Geometric() public méthode

Conceptually, generates either 1 or 0 until a 1 is generated, and counts the number of 0's generated. Either number has an equal probability of being generated.
public Geometric ( ) : int
Résultat int

Geometric() public méthode

Conceptually, generates either 1 or 0 until a 1 is generated, and counts the number of 0's generated. A 1 is generated at the given probability.
public Geometric ( double p ) : int
p double A 64-bit floating-point number.
Résultat int

Hypergeometric() public méthode

Conceptually, given a set of tokens, some of which are labeled 1 and the others labeled 0, draws "trials" tokens at random without replacement and then counts the number of 1's drawn.
public Hypergeometric ( int trials, int ones, int count ) : int
trials int The number of tokens drawn at random without /// replacement.
ones int The number of tokens labeled 1.
count int The number of tokens labeled 1 or 0.
Résultat int

LogNormal() public méthode

Generates a logarithmic normally-distributed number with the given mean and standard deviation.
public LogNormal ( double mean, double sd ) : double
mean double The desired mean.
sd double Standard deviation.
Résultat double

NegativeBinomial() public méthode

Conceptually, generates either 1 or 0 the given number of times until the given number of 1's are generated, and counts the number of 0's generated. Either number has an equal probability of being generated.
public NegativeBinomial ( int trials ) : int
trials int The number of 1's to generate before the /// process stops.
Résultat int

NegativeBinomial() public méthode

Conceptually, generates either 1 or 0 until the given number of 1's are generated, and counts the number of 0's generated. A 1 is generated at the given probability.
public NegativeBinomial ( int trials, double p ) : int
trials int The number of 1's to generate before the /// process stops.
p double The probability for each trial to succeed, from 0 /// (never) to 1 (always).
Résultat int

Normal() public méthode

Generates a normally-distributed number with mean 0 and standard deviation 1.
public Normal ( ) : double
Résultat double

Normal() public méthode

Generates a normally-distributed number with the given mean and standard deviation.
public Normal ( double mean, double sd ) : double
mean double The desired mean.
sd double Standard deviation.
Résultat double

Poisson() public méthode

Generates a random integer such that the average of random numbers approaches the given mean number when this method is called repeatedly with the same mean.
public Poisson ( double mean ) : int
mean double The expected mean of the random numbers.
Résultat int

RandomGenerator() public méthode

Initializes a new instance of the RandomGenerator class.
public RandomGenerator ( ) : System
Résultat System

RandomGenerator() public méthode

Initializes a new instance of the RandomGenerator class.
public RandomGenerator ( IRandomGen valueIrg ) : System
valueIrg IRandomGen An IRandomGen object.
Résultat System

Uniform() public méthode

Returns a uniformly-distributed 64-bit floating-point number from 0 and up, but less than 1.
public Uniform ( ) : double
Résultat double

Uniform() public méthode

Returns a uniformly-distributed 64-bit floating-point number from 0 and up, but less than the given number.
public Uniform ( double max ) : double
max double Number that the randomly-generated number will be /// less than.
Résultat double

Uniform() public méthode

Not documented yet.
public Uniform ( double min, double max ) : double
min double Smallest possible number that will be /// generated.
max double Number that the randomly-generated number will be /// less than.
Résultat double

UniformInt() public méthode

Generates a random 32-bit signed integer 0 or greater and less than the given number.
public UniformInt ( int maxExclusive ) : int
maxExclusive int One plus the largest possible value of /// the random number.
Résultat int

UniformInt() public méthode

Generates a random 32-bit signed integer within a given range.
public UniformInt ( int minInclusive, int maxExclusive ) : int
minInclusive int Smallest possible value of the random /// number.
maxExclusive int One plus the largest possible value of /// the random number.
Résultat int

UniformLong() public méthode

Generates a random 32-bit signed integer 0 or greater and less than the given number.
public UniformLong ( long maxExclusive ) : long
maxExclusive long One plus the largest possible value of /// the random number.
Résultat long

UniformLong() public méthode

Generates a random 64-bit signed integer within a given range.
public UniformLong ( long minInclusive, long maxExclusive ) : long
minInclusive long Smallest possible value of the random /// number.
maxExclusive long One plus the largest possible value of /// the random number.
Résultat long

UniformSingle() public méthode

Returns a uniformly-distributed 32-bit floating-point number from 0 and up, but less than 1.
public UniformSingle ( ) : double
Résultat double