View source code
Display the source code in std/random.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Enum member std.random.isUniformRNG

Test if Rng is a random-number generator. The overload taking a ElementType also makes sure that the Rng generates values of that type.

enum isUniformRNG(Rng, ElementType) = isInputRange!Rng && is(typeof(Rng.front) == ElementType) && is(typeof(() { static assert(Rng.isUniformRandom); } ));
enum isUniformRNG(Rng) = isInputRange!Rng && is(typeof(() { static assert(Rng.isUniformRandom); } ));

A random-number generator has at least the following features:

  • it's an InputRange
  • it has a 'bool isUniformRandom' field readable in CTFE

Example

struct NoRng
{
    @property uint front() {return 0;}
    @property bool empty() {return false;}
    void popFront() {}
}
static assert(!isUniformRNG!(NoRng));

struct validRng
{
    @property uint front() {return 0;}
    @property bool empty() {return false;}
    void popFront() {}

    enum isUniformRandom = true;
}
static assert(isUniformRNG!(validRng, uint));
static assert(isUniformRNG!(validRng));

Authors

Andrei Alexandrescu Masahiro Nakagawa (Xorshift random generator) Joseph Rushton Wakeling (Algorithm D for random sampling) Ilya Yaroshenko (Mersenne Twister implementation, adapted from mir-random)

License

Boost License 1.0.