mir-random 0.4.2

Dlang Random Number Generators


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

dub.json
dub.sdl

Dub version Dub downloads License

Circle CI Build Status Build status Gitter

mir-random

Professional Random Number Generators

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

Example (3 seconds)

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

import std.range, std.stdio;

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

void main()
{
    auto sample = NormalVariable!double(0, 1).range.take(10).array;

    sample[$.randIndex].writeln; // prints random element from the sample
}

Open on run.dlang.io

Example (10 seconds)

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

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 = range!rng                      // Engines can passed to algorithms by alias or by pointer
        (NormalVariable!double(0, 1))            // Random variables are passed by value
        .take(10)                                // Fix sample length to 10 elements (Input Range API)
        .array;                                  // Allocates memory and performs computation

    sample[$.randIndex].writeln;                 // prints random element from the sample
}

Open on run.dlang.io

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.
  • Additional optimization was added for enumerated types.
  • Random nd-array (ndslice) generation.
  • Bounded integer generation in randIndex uses Daniel Lemire's fast alternative to modulo reduction. The throughput increase measured for randIndex!uint on an x86-64 processor compiled with LDC 1.6.0 was 1.40x for Mt19937_64 and 1.73x for Xoroshiro128Plus. The throughput increase measured for randIndex!ulong was 2.36x for Mt19937_64 and 4.25x for Xoroshiro128Plus.
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)
  • SplitMix generators (new)
  • XorshiftStar Generators (new)
  • Xoroshiro128Plus generator (new)
Authors:
  • Ilya Yaroshenko
  • Sebastian Wilzbach
  • Nathan Sashihara
  • Andrei Alexandrescu
  • Masahiro Nakagawa
  • Nicholas Wilson
Dependencies:
mir-linux-kernel, mir-algorithm
Versions:
0.4.7 2018-Jun-14
0.4.6 2018-Jun-13
0.4.5 2018-Mar-28
0.4.4 2018-Mar-09
0.4.3 2018-Feb-20
Show all 36 versions
Download Stats:
  • 12 downloads today

  • 88 downloads this week

  • 476 downloads this month

  • 8456 downloads total

Score:
4.2
Short URL:
mir-random.dub.pm