mir-random 0.2.8

Dlang Random Number Generators

To use this package, put the following dependency into your project's dependencies section:



Circle CI Build Status Build status

Dub version Dub downloads License


Professional Random Number Generators

Documentation: http://docs.random.dlang.io/latest/index.html

#!/usr/bin/env dub
/+ dub.json:
    "name": "test_random",
    "dependencies": {"mir-random": "~>0.2.5"}

import std.range, std.stdio;

import mir.random;
import mir.random.variable: NormalVariable;
import mir.random.algorithm: range;

void main(){
    auto rng = Random(unpredictableSeed);        // Engines are allocated on stack or global
    auto sample = rng                            // Engines are passed by reference to algorithms
        .range(NormalVariable!double(0, 1))      // Random variables are passed by value
        .take(1000)                              // Fix sample length to 1000 elements (Input Range API)
        .array;                                  // Allocates memory and performs computation


Comparison with Phobos

  • Does not depend on DRuntime (Better C concept)

random (new implementation and API)
  • Mir Random rand!float/rand!double/rand!real generates saturated real random numbers in (-1, 1). For example, rand!real can produce more than 2^78 unique numbers. In other hand, std.random.uniform01!real produces less than 2^31 unique numbers with default Engine.
  • Mir Random fixes Phobos integer underflow bugs.
  • Addition optimization was added for enumerated types.
  • Random nd-array (ndslice) generation.
random.variable (new)
  • Uniform
  • Exponential
  • Gamma
  • Normal
  • Cauchy
  • ...
random.ndvariable (new)
  • Simplex
  • Sphere
  • Multivariate Normal
  • ...
random.algorithm (new)
  • Ndslice and range API adaptors

random.engine.* (fixed, reworked, new)
  • opCall API instead of range interface is used (similar to C++)
  • No default and copy constructors are allowed for generators.
  • unpredictableSeed has not state, returns size_t
  • Any unsigned generators are allowed.
  • min property was removed. Any integer generator can normalize its minimum down to zero.
  • Mt19937: +100% performance for initialization. (merged to Phobos)
  • Mt19937: +54% performance for generation. (merged to Phobos)
  • Mt19937: fixed to be more CPU cache friendly. (merged to Phobos)
  • 64-bit Mt19937 initialization is fixed (merged to Phobos)
  • 64-bit Mt19937 is default for 64-bit targets
  • Permuted Congruential Generators (new)
  • XorshiftStar Generators (new)
Ilya Yaroshenko, Sebastian Wilzbach, Andrei Alexandrescu, Masahiro Nakagawa, Nicholas Wilson
0.2.8 2017-Oct-24
0.2.7 2017-Oct-04
0.2.6 2017-Sep-27
0.2.5 2017-May-18
0.2.4 2017-May-02
Show all 20 versions
Download Stats:
  • 5 downloads today

  • 46 downloads this week

  • 98 downloads this month

  • 1821 downloads total