RandomG

Class that represents a random number generator. Normally you should get random numbers either with call-like interface: auto r=new Random(); r(i)(j)(k); or with randomize r.randomize(i); r.randomize(j); r.randomize(k); if you use this you should be able to easily switch distribution later, as all distributions support this interface, and can be built on the top of RandomG auto r2=r.NormalSource!(float)(); r2(i)(j)(k); there are utility methods within random for the cases in which you do not want to build a special distribution for just a few numbers

final
class RandomG (
SourceT = DefaultEngine
) {}

Constructors

this
this(bool randomInit)

Creates and seeds a new generator

Members

Functions

exp
T exp()

returns an exp distribued number

expBeta
T expBeta(T beta)

returns an exp distribued number with the given scale beta

expD
ExpSource!(RandomG, T).ExpDistribution expD(T beta)

exponential distribued numbers with a different default beta f=1/beta*exp(-x/beta)

expSource
ExpSource!(RandomG, T) expSource()

generators of exp distribued numbers (beta=1) of the given type f=1/beta*exp(-x/beta)

fromString
size_t fromString(const(char[]) s)

reads the current status from a string (that should have been trimmed) returns the number of chars read

gamma
T gamma(T alpha, T sigma)

returns a gamma distribued number from Marsaglia and Tsang, ACM Transaction on Mathematical Software, Vol. 26, N. 3 2000, p 363-372

gammaD
GammaDistribution!(T) gammaD(T alpha, T theta)

gamma distribued numbers with the given default alpha

getRandom
T getRandom()

returns a random number

next
uint next()
uint next(uint to)
uint next(uint from, uint to)

compatibility with old Random, deprecate??

normal
T normal()

returns a normal distribued number

normalD
NormalSource!(RandomG, T).NormalDistribution normalD(T sigma, T mu)

generators of normal numbers with a different default sigma/mu f=exp(-x*x/(2*sigma^2))/(sqrt(2 pi)*sigma)

normalSigma
T normalSigma(T sigma)

returns a normal distribued number with the given sigma

normalSigmaMu
T normalSigmaMu(T sigma, T mu)

returns a normal distribued number with the given sigma and mu

normalSource
NormalSource!(RandomG, T) normalSource()

generators of normal numbers (sigma=1,mu=0) of the given type f=exp(-x*x/(2*sigma^2))/(sqrt(2 pi)*sigma)

opCall
RandomG opCall(U a)

chainable call style initialization of variables (thorugh a call to randomize)

randomize
U randomize(U a)

initialize el

randomizeUniform
U randomizeUniform(U a)

randomizes the given array and returns it (for some types this is potentially more efficient, both from the use of random numbers and speedwise)

randomizeUniformR
U randomizeUniformR(U a, V to)

randomizes the given array and returns it (for some types this is potentially more efficient, both from the use of random numbers and speedwise)

randomizeUniformR2
U randomizeUniformR2(U a, V from, W to)

randomizes the given variable and returns it (for some types this is potentially more efficient, both from the use of random numbers and speedwise)

randomizeUniformRSymm
U randomizeUniformRSymm(U a, V to)

randomizes the given variable like uniformRSymm and returns it (for some types this is potentially more efficient, both from the use of random numbers and speedwise)

seed
RandomG seed()

if source.canSeed seeds the generator using the shared rand generator (use urandom directly if available?)

seed
RandomG seed(uint delegate() seedSource)

if source.canSeed seeds the generator using the given source of uints

spawn
RandG spawn()

returns another (mostly indipendent, depending on seed size) random generator

toString
string toString()

writes the current status in a string

uniformBoundsD
UniformDistribution!(T, false) uniformBoundsD()

uniform distribution on the whole integer range, and on [0;1] for floats

uniformD
UniformDistribution!(T, true) uniformD()

uniform distribution on the whole integer range, and on (0;1) for floats should return simply this??

uniformEl
T uniformEl(const(T[]) arr)

returns a random element of the given array (which must be non empty)

uniformR
T uniformR(T to)

uniform distribution on the range [0;to) for integer types, and on the (0;to) range for floating point types. Same caveat as uniform(T) apply

uniformR2
T uniformR2(T from, T to)

uniform distribution [from;to) for integers, and (from;to) for floating point numbers. if boundCheck is false the bounds are included in the floating point number distribution. the range for int and long is limited to only half the possible range (it could be worked around using long aritmethic for int, and doing a carry by hand for long, but I think it is seldomly needed, for int you are better off using long when needed)

uniformR2BoundsD
UniformR2Distribution!(T, false) uniformR2BoundsD(T from, T to)

uniform distribution [from;to) for ints and [from;to] for reals

uniformR2D
UniformR2Distribution!(T, true) uniformR2D(T from, T to)

uniform distribution [from;to) for ints and (from;to) for reals

uniformRBoundsD
UniformRDistribution!(T, false) uniformRBoundsD(T to)

uniform distribution [0;to) for ints, [0:to] for reals

uniformRD
UniformRDistribution!(T, true) uniformRD(T to)

uniform distribution [0;to) for ints, (0:to) for reals

uniformRSymm
T uniformRSymm(T to, int iter)

uniform distribution on the range (-to;to) for integer types, and on the (-to;0)(0;to) range for floating point types if boundCheck is true. If boundCheck=false the range changes to [-to;0)u(0;to] with a slightly lower propability at the bounds for floating point numbers. excludeZero controls if 0 is excluded or not (by default float exclude it, ints no). Please note that the probability of 0 in floats is very small due Cannot be used on unsigned types.

uniformRSymmBoundsD
UniformRSymmDistribution!(T, false, isFloat!(T)) uniformRSymmBoundsD(T to)

uniform distribution (-to;to) for ints and [-to;0)u(0;to] for reals

uniformRSymmD
UniformRSymmDistribution!(T, true, isFloat!(T)) uniformRSymmD(T to)

uniform distribution (-to;to) for ints and (-to;0)u(0;to) for reals

Properties

uniform
T uniform [@property getter]

uniform distribution on the whole range of integer types, and on the (0;1) range for floating point types. Floating point guarantees the initialization of the full mantissa, but due to rounding effects it might have *very* small dependence due to rounding effects on the least significant bit (in case of tie 0 is favored). if boundCheck is false in the floating point case bounds might be included (but with a lower propability than other numbers)

Static functions

instance
RandomG!(Sync!(DefaultEngine)) instance()

compatibility with old Random, deprecate??

Structs

GammaDistribution
struct GammaDistribution(T)

gamma distribution f=x^(alpha-1)*exp(-x/theta)/(gamma(alpha)*theta^alpha) alpha has to be bigger than 1, for alpha<1 use gammaD(alpha)=gammaD(alpha+1)*pow(r.uniform!(T),1/alpha) from Marsaglia and Tsang, ACM Transaction on Mathematical Software, Vol. 26, N. 3 2000, p 363-372

UniformDistribution
struct UniformDistribution(T, bool boundCheck)

uniform distribution on the whole range for integers, and on (0;1) for floats with boundCheck=true this is equivalent to r itself, here just for completness

UniformR2Distribution
struct UniformR2Distribution(T, bool boundCheck)

uniform distribution on the subrange (-to;to) for integers, (0;to) for floats

UniformRDistribution
struct UniformRDistribution(T, bool boundCheck)

uniform distribution on the subrange [0;to) for integers, (0;to) for floats

UniformRSymmDistribution
struct UniformRSymmDistribution(T, bool boundCheck = true, bool excludeZero = isFloat!(T))

uniform distribution on the subrange (-to;to) for integers, (-to;0)u(0;to) for floats excludeZero controls if the zero should be excluded, boundCheck if the boundary should be excluded for floats

Variables

expDouble
ExpSource!(RandomG, double) expDouble;
Undocumented in source.
expFloat
ExpSource!(RandomG, float) expFloat;
Undocumented in source.
expReal
ExpSource!(RandomG, real) expReal;
Undocumented in source.
normalDouble
NormalSource!(RandomG, double) normalDouble;
Undocumented in source.
normalFloat
NormalSource!(RandomG, float) normalFloat;
Undocumented in source.
normalReal
NormalSource!(RandomG, real) normalReal;
Undocumented in source.
source
SourceT source;
Undocumented in source.

Meta