hap.random.distribution

Implements algorithms for generating random numbers drawn from different statistical distributions. Where possible, each random distribution is provided in two different forms:

  • as a function, which takes as input the distribution parameters and a uniform RNG, and returns a single value drawn from the distribution, and
  • as a range object, which wraps a uniform RNG instance and transforms its output into numbers drawn from the specified distribution.

Typical reasons for rejecting a function implementation include the function needing to hold state between calls to achieve adequate performance, or the function needing to allocate memory with each call.

As with random number generators, the random distribution range objects implemented here are final classes in order to ensure reference semantics. They also assume reference type semantics on the part of the RNGs that they wrap: user-supplied value-type RNGs may produce unexpected and incorrect behaviour when combined with these objects.

Note: hap._random._distribution.dice uses a different algorithm to its std.random counterpart and so will produce different results.

Members

Classes

DiscreteDistribution
class DiscreteDistribution(SearchPolicy search, T, UniformRNG)

The range equivalent of dice, each element of which is the result of the roll of a random die with relative probabilities stored in the range proportions. Each successive value of front reflects the index in proportions that was chosen. If no random number generator is specified, the default rndGen will be used as the source of randomness.

NormalDistribution
class NormalDistribution(T, UniformRNG)

Provides an infinite range of random numbers distributed according to the normal (Gaussian) distribution with mean mu and standard deviation sigma. If no random number generator is specified, the default rndGen will be used as the source of randomness.

Uniform01Distribution
class Uniform01Distribution(T, UniformRNG)

Provides an infinite sequence of random numbers uniformly distributed in the interval [0, 1). If no RNG is specified, uniformDistribution will use the default generator rndGen.

UniformDistribution
class UniformDistribution(string boundaries = "[)", T, UniformRNG)

Provides an infinite sequence of random numbers uniformly distributed between a and b. The boundaries parameter controls the shape of the interval (open vs. closed on either side). Valid values for boundaries are "[]", "$(LPAREN)]", "[$(RPAREN)", and "()". The default interval is closed to the left and open to the right. If no random number generator is specified, the default rndGen will be used as the source of randomness.

UniformDistribution
class UniformDistribution(T, UniformRNG)

Generates an infinite sequence of uniformly-distributed numbers in the range [T.min, T.max] for any integral type T. If no random number generator is specified, the default rndGen will be used as the source of randomness.

UniformDistribution
class UniformDistribution(E, UniformRNG)

Generates an infinite sequence of uniformly selected members of enum E. If no random number generator is specified, the default rndGen will be used as the source of randomness.

Functions

dice
size_t dice(UniformRNG rng, Num[] proportions)
size_t dice(UniformRNG rng, Range proportions)
size_t dice(Range proportions)
size_t dice(Num[] proportions)

Rolls a random die with relative probabilities stored in proportions. Returns the index in proportions that was chosen.

discreteDistribution
auto discreteDistribution(UniformRNG rng, Range proportions)
auto discreteDistribution(Range proportions)
auto discreteDistribution(UniformRNG rng, Num[] proportions)
auto discreteDistribution(Num[] proportions)

The range equivalent of dice, each element of which is the result of the roll of a random die with relative probabilities stored in the range proportions. Each successive value of front reflects the index in proportions that was chosen. If no random number generator is specified, the default rndGen will be used as the source of randomness.

normal
auto normal(T1 mu, T2 sigma)
auto normal(T1 mu, T2 sigma, UniformRNG rng)

Returns a floating-point number drawn from a normal (Gaussian) distribution with mean mu and standard deviation sigma. If no random number generator is specified, the default rndGen will be used as the source of randomness.

normalDistribution
auto normalDistribution(T1 mu, T2 sigma, UniformRNG rng)
auto normalDistribution(T1 mu, T2 sigma)

Provides an infinite range of random numbers distributed according to the normal (Gaussian) distribution with mean mu and standard deviation sigma. If no random number generator is specified, the default rndGen will be used as the source of randomness.

uniform
auto uniform(T1 a, T2 b)
auto uniform(T1 a, T2 b, UniformRNG rng)

Generates a number between a and b. The boundaries parameter controls the shape of the interval (open vs. closed on either side). Valid values for boundaries are "[]", "$(LPAREN)]", "[$(RPAREN)", and "()". The default interval is closed to the left and open to the right. If no random number generator is specified, the default rndGen will be used as the source of randomness.

uniform
auto uniform(UniformRNG rng)
auto uniform()

Generates a uniformly-distributed number in the range [T.min, T.max] for any integral type T. If no random number generator is passed, uses the default rndGen.

uniform
auto uniform(UniformRNG rng)

Returns a uniformly selected member of enum E. If no random number generator is passed, uses the default rndGen.

uniform01
T uniform01()
T uniform01(UniformRNG rng)

Generates a uniformly-distributed floating point number of type T in the range [0, 1). If no random number generator is specified, the default RNG rndGen will be used as the source of randomness.

uniform01Distribution
auto uniform01Distribution(UniformRNG rng)
auto uniform01Distribution()

Provides an infinite sequence of random numbers uniformly distributed in the interval [0, 1). If no RNG is specified, uniformDistribution will use the default generator rndGen.

uniformDistribution
auto uniformDistribution(T1 a, T2 b, UniformRNG rng)
auto uniformDistribution(T1 a, T2 b)

Provides an infinite sequence of random numbers uniformly distributed between a and b. The boundaries parameter controls the shape of the interval (open vs. closed on either side). Valid values for boundaries are "[]", "$(LPAREN)]", "[$(RPAREN)", and "()". The default interval is closed to the left and open to the right. If no random number generator is specified, the default rndGen will be used as the source of randomness.

uniformDistribution
auto uniformDistribution(UniformRNG rng)
auto uniformDistribution()

Generates an infinite sequence of uniformly-distributed numbers in the range [T.min, T.max] for any integral type T. If no random number generator is specified, the default rndGen will be used as the source of randomness.

uniformDistribution
auto uniformDistribution(UniformRNG rng)

Generates an infinite sequence of uniformly selected members of enum E. If no random number generator is specified, the default rndGen will be used as the source of randomness.

Templates

DiceType
template DiceType(Range)
Undocumented in source.
DiceType
template DiceType(T)
Undocumented in source.

Meta

Source

See Source File
$(HAPSRC hap/random/_distribution.d)

Authors

Andrei Alexandrescu, Chris Cain (discrete distribution and integral-based uniform), Andrej Mitrović (enum-based uniform), Joseph Rushton Wakeling