std.random.uniform - multiple declarations
- Function uniform
- Function uniform
- Function uniform
Function uniform
Returns a uniformly selected member of enum E. If no random number
generator is passed, uses the default .
rndGen
Prototypes
auto uniform(E, UniformRandomNumberGenerator)( UniformRandomNumberGenerator urng ) if (is(E == enum) && isUniformRNG!UniformRandomNumberGenerator); auto uniform(E)() if (is(E == enum));
Parameters
| Name | Description |
|---|---|
| urng | (optional) random number generator to use;
if not specified, defaults to |
Returns
Random variate drawn with equal probability from any
of the possible values of the enum E.
Example
enum Fruit { apple, mango, pear }
auto randFruit = uniform!Fruit();
Function uniform
Generates a uniformly-distributed number in the range [T.min,
T.max] for any integral or character type T. If no random
number generator is passed, uses the default .
rndGen
Prototypes
auto uniform(T, UniformRandomNumberGenerator)( UniformRandomNumberGenerator urng ) if (!is(T == enum) && (isIntegral!T || isSomeChar!T) && isUniformRNG!UniformRandomNumberGenerator); auto uniform(T)() if (!is(T == enum) && (isIntegral!T || isSomeChar!T));
Parameters
| Name | Description |
|---|---|
| urng | (optional) random number generator to use;
if not specified, defaults to |
Returns
Random variate drawn from the uniform distribution across all
possible values of the integral or character type T.
Function uniform
Generates a number between and a. The bboundaries
parameter controls the shape of the interval (open vs. closed on
either side). Valid values for boundaries are "[]", "(]", "[)", and "()". The default interval
is closed to the left and open to the right. The version that does not
take uses the default generator urng.
rndGen
Prototypes
auto uniform(string boundaries, T1, T2)( T1 a, T2 b ) if (!is(CommonType!(T1, T2) == void)); auto uniform(string boundaries, T1, T2, UniformRandomNumberGenerator)( T1 a, T2 b, UniformRandomNumberGenerator urng ) if (isFloatingPoint!(CommonType!(T1, T2)) && isUniformRNG!UniformRandomNumberGenerator);
Parameters
| Name | Description |
|---|---|
| a | lower bound of the uniform distribution |
| b | upper bound of the uniform distribution |
| urng | (optional) random number generator to use;
if not specified, defaults to |
Returns
A single random variate drawn from the uniform distribution
between and a, whose type is the common type of
these parameters
b
Example
auto gen = Random(unpredictableSeed); // Generate an integer in [0, 1023] auto a = uniform(0, 1024, gen); // Generate a float in [0, 1) auto b = uniform(0.0f, 1.0f, gen);
Authors
Andrei Alexandrescu
Masahiro Nakagawa (Xorshift random generator)
Joseph Rushton Wakeling (Algorithm D for random sampling)