C# Класс 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.

Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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.

Приватные методы

Метод Описание
NonZeroUniform ( ) : double

Описание методов

Bernoulli() публичный Метод

Returns either true or false at a 50% chance each.
public Bernoulli ( ) : bool
Результат bool

Bernoulli() публичный Метод

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.
Результат bool

Binomial() публичный Метод

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.
Результат int

Binomial() публичный Метод

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).
Результат int

ChiSquared() публичный Метод

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).
Результат double

Exponential() публичный Метод

Not documented yet.
public Exponential ( ) : double
Результат double

Gamma() публичный Метод

Not documented yet.
public Gamma ( double a ) : double
a double Another 64-bit floating-point number.
Результат double

Gamma() публичный Метод

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).
Результат double

Geometric() публичный Метод

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
Результат int

Geometric() публичный Метод

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.
Результат int

Hypergeometric() публичный Метод

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.
Результат int

LogNormal() публичный Метод

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.
Результат double

NegativeBinomial() публичный Метод

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.
Результат int

NegativeBinomial() публичный Метод

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).
Результат int

Normal() публичный Метод

Generates a normally-distributed number with mean 0 and standard deviation 1.
public Normal ( ) : double
Результат double

Normal() публичный Метод

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.
Результат double

Poisson() публичный Метод

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.
Результат int

RandomGenerator() публичный Метод

Initializes a new instance of the RandomGenerator class.
public RandomGenerator ( ) : System
Результат System

RandomGenerator() публичный Метод

Initializes a new instance of the RandomGenerator class.
public RandomGenerator ( IRandomGen valueIrg ) : System
valueIrg IRandomGen An IRandomGen object.
Результат System

Uniform() публичный Метод

Returns a uniformly-distributed 64-bit floating-point number from 0 and up, but less than 1.
public Uniform ( ) : double
Результат double

Uniform() публичный Метод

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.
Результат double

Uniform() публичный Метод

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.
Результат double

UniformInt() публичный Метод

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.
Результат int

UniformInt() публичный Метод

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.
Результат int

UniformLong() публичный Метод

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.
Результат long

UniformLong() публичный Метод

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.
Результат long

UniformSingle() публичный Метод

Returns a uniformly-distributed 32-bit floating-point number from 0 and up, but less than 1.
public UniformSingle ( ) : double
Результат double