C# Класс RandomOps.Random

Implements a Gaussian RNG using the Uniform() method.
Показать файл Открыть проект Примеры использования класса

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

Метод Описание
Bool ( ) : bool

Draw a random boolean with equal probability of true or false. Thread-safe if Uniform() is thread-safe.

Bool ( double p ) : bool

Draw a random boolean with probability p of true and (1-p) of false. Thread-safe if Uniform() is thread-safe.

Byte ( ) : byte

Draw a random and uniform byte. Thread-safe if Index() is thread-safe.

The default implementation uses Index() which in turn uses Uniform(). This is quite expensive for generating just one byte, but is the most generally viable way of doing it for many PRNGs, because their low-order bits are not very random. Some PRNGs may offer much better ways of generating just a single random byte, in which case this method should of course be overrided.

Bytes ( int length ) : byte[]

Draw an array of random and uniform bytes. Thread-safe if Byte() is thread-safe.

Circle ( ) : double[]

Generate a uniform random point from the unit-radius 2-dimensional circle. Thread-safe if Disk() is thread-safe.

Circle ( double &x, double &y ) : void

Generate a uniform random point from the unit-radius 2-dimensional circle. Thread-safe if Disk() is thread-safe.

Disk ( ) : double[]

Generate a uniform random point from the unit-radius 2-dimensional disk. Thread-safe if Uniform() is thread-safe.

Disk ( double &x, double &y, double &sumSquares ) : void

Generate a uniform random point from the unit-radius 2-dimensional disk. Thread-safe if Uniform() is thread-safe.

Gauss ( ) : double

Draw a Gaussian (or normally) distributed random number, with mean 0 and deviation 1. Not thread-safe.

Gauss ( double mean, double deviation ) : double

Draw a Gaussian (or normally) distributed random number, with designated mean and deviation. Thread-safe if Gauss() is thread-safe.

Index ( double probabilities ) : int

Draw a random integer from the set {0, .., n-1} according to the supplied probability distribution. Probabilities are assumed to sum to one. Time-complexity is O(n), where n is the length of the probabilities-array. Use this function if you only need to draw a few random numbers, otherwise create an IndexDistribution-object. Thread-safe if Uniform() is thread-safe.

Index ( int n ) : int

Draw a random integer from the set {0, .., n-1} with uniform probability. Thread-safe if Uniform() is thread-safe.

The default implementation uses Uniform() to generate an integer. This is because many PRNGs must use division instead of modulo arithmetics due to the lower-order bits having little randomness. Assume Uniform cannot generate an exact value of one, otherwise this must have been taken into account to ensure uniform probability of choosing the different indices.

Index2 ( int n, int &index1, int &index2 ) : void

Draw two distinct integers from the set {0, .., n-1} with equal probability. Thread-safe if Uniform() is thread-safe.

Sphere ( int n, double r ) : double[]

Generate a uniform random point on the n-dimensional hypersphere. Thread-safe if Gauss() is thread-safe.

Sphere ( double &x, double r ) : void

Generate a uniform random point on the n-dimensional hypersphere. Thread-safe if Gauss() is thread-safe, and each thread supplies its own array x.

Sphere3 ( ) : double[]

Generate a uniform random point on the unit-radius 3-dimensional sphere. Thread-safe if Disk() is thread-safe.

Sphere3 ( double &x ) : void

Generate a uniform random point on the unit-radius 3-dimensional sphere. Thread-safe if Disk() is thread-safe.

Sphere4 ( ) : double[]

Generate a uniform random point on the unit-radius 4-dimensional sphere. Thread-safe if Disk() is thread-safe.

Sphere4 ( double &x ) : void

Generate a uniform random point on the unit-radius 4-dimensional sphere. Thread-safe if Disk() is thread-safe.

Uniform ( ) : double

Draw a uniform random number in the exclusive range (0,1).

This must be implemented in every inherited class. It is important that it does not return the end-point values of zero or one, or else some of the methods which use Uniform() to generate their random numbers will not work.

Uniform ( double low, double high ) : double

Draw a uniform random number in the exclusive range (low,high). Thread-safe if Uniform() is thread-safe.

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

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

Draw a random boolean with equal probability of true or false. Thread-safe if Uniform() is thread-safe.
public Bool ( ) : bool
Результат bool

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

Draw a random boolean with probability p of true and (1-p) of false. Thread-safe if Uniform() is thread-safe.
public Bool ( double p ) : bool
p double
Результат bool

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

Draw a random and uniform byte. Thread-safe if Index() is thread-safe.
The default implementation uses Index() which in turn uses Uniform(). This is quite expensive for generating just one byte, but is the most generally viable way of doing it for many PRNGs, because their low-order bits are not very random. Some PRNGs may offer much better ways of generating just a single random byte, in which case this method should of course be overrided.
public Byte ( ) : byte
Результат byte

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

Draw an array of random and uniform bytes. Thread-safe if Byte() is thread-safe.
public Bytes ( int length ) : byte[]
length int The array length requested.
Результат byte[]

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

Generate a uniform random point from the unit-radius 2-dimensional circle. Thread-safe if Disk() is thread-safe.
public Circle ( ) : double[]
Результат double[]

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

Generate a uniform random point from the unit-radius 2-dimensional circle. Thread-safe if Disk() is thread-safe.
public Circle ( double &x, double &y ) : void
x double Random point x
y double Random point y
Результат void

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

Generate a uniform random point from the unit-radius 2-dimensional disk. Thread-safe if Uniform() is thread-safe.
public Disk ( ) : double[]
Результат double[]

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

Generate a uniform random point from the unit-radius 2-dimensional disk. Thread-safe if Uniform() is thread-safe.
public Disk ( double &x, double &y, double &sumSquares ) : void
x double Random point x
y double Random point y
sumSquares double Equals x*x + y*y
Результат void

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

Draw a Gaussian (or normally) distributed random number, with mean 0 and deviation 1. Not thread-safe.
public Gauss ( ) : double
Результат double

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

Draw a Gaussian (or normally) distributed random number, with designated mean and deviation. Thread-safe if Gauss() is thread-safe.
public Gauss ( double mean, double deviation ) : double
mean double The mean of the distribution, e.g. 0.
deviation double The deviation of the distribution, e.g. 1.
Результат double

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

Draw a random integer from the set {0, .., n-1} according to the supplied probability distribution. Probabilities are assumed to sum to one. Time-complexity is O(n), where n is the length of the probabilities-array. Use this function if you only need to draw a few random numbers, otherwise create an IndexDistribution-object. Thread-safe if Uniform() is thread-safe.
public Index ( double probabilities ) : int
probabilities double Probability distribution.
Результат int

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

Draw a random integer from the set {0, .., n-1} with uniform probability. Thread-safe if Uniform() is thread-safe.
The default implementation uses Uniform() to generate an integer. This is because many PRNGs must use division instead of modulo arithmetics due to the lower-order bits having little randomness. Assume Uniform cannot generate an exact value of one, otherwise this must have been taken into account to ensure uniform probability of choosing the different indices.
public Index ( int n ) : int
n int
Результат int

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

Draw two distinct integers from the set {0, .., n-1} with equal probability. Thread-safe if Uniform() is thread-safe.
public Index2 ( int n, int &index1, int &index2 ) : void
n int
index1 int Reference to the first integer drawn.
index2 int Reference to the second integer drawn.
Результат void

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

Generate a uniform random point on the n-dimensional hypersphere. Thread-safe if Gauss() is thread-safe.
public Sphere ( int n, double r ) : double[]
n int Dimensionality of hypersphere.
r double Radius of hypersphere.
Результат double[]

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

Generate a uniform random point on the n-dimensional hypersphere. Thread-safe if Gauss() is thread-safe, and each thread supplies its own array x.
public Sphere ( double &x, double r ) : void
x double Array to hold the random point.
r double Radius of hypersphere.
Результат void

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

Generate a uniform random point on the unit-radius 3-dimensional sphere. Thread-safe if Disk() is thread-safe.
public Sphere3 ( ) : double[]
Результат double[]

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

Generate a uniform random point on the unit-radius 3-dimensional sphere. Thread-safe if Disk() is thread-safe.
public Sphere3 ( double &x ) : void
x double Array to hold the random point.
Результат void

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

Generate a uniform random point on the unit-radius 4-dimensional sphere. Thread-safe if Disk() is thread-safe.
public Sphere4 ( ) : double[]
Результат double[]

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

Generate a uniform random point on the unit-radius 4-dimensional sphere. Thread-safe if Disk() is thread-safe.
public Sphere4 ( double &x ) : void
x double Array to hold the random point.
Результат void

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

Draw a uniform random number in the exclusive range (0,1).
This must be implemented in every inherited class. It is important that it does not return the end-point values of zero or one, or else some of the methods which use Uniform() to generate their random numbers will not work.
public abstract Uniform ( ) : double
Результат double

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

Draw a uniform random number in the exclusive range (low,high). Thread-safe if Uniform() is thread-safe.
public Uniform ( double low, double high ) : double
low double The lowest value in the range.
high double The highest value in the range.
Результат double