rand

  1. T rand(G gen)
  2. T rand(G* gen)
  3. T rand()
  4. bool rand(G gen)
  5. bool rand(G* gen)
  6. bool rand()
  7. T rand(G gen)
  8. T rand(G* gen)
  9. T rand()
  10. T rand(G gen, sizediff_t boundExp)
    T
    rand
    (
    T
    G
    )
    (
    scope ref G gen
    ,
    sizediff_t boundExp = 0
    )
    if (
    isSaturatedRandomEngine!G &&
    isFloatingPoint!T
    )
  11. T rand(G* gen, sizediff_t boundExp)
  12. T rand(sizediff_t boundExp)

Parameters

gen G

saturated random number generator

boundExp sizediff_t

bound exponent (optional). boundExp must be less or equal to T.max_exp.

Return Value

Type: T

Uniformly distributed real for interval (-2^^boundExp , 2^^boundExp). Note: fabs can be used to get a value from positive interval [0, 2^^boundExp$(RPAREN).

Examples

import mir.math.common: fabs;

auto a = rand!float;
assert(-1 < a && a < +1);

auto b = rand!double(4);
assert(-16 < b && b < +16);

auto c = rand!double(-2);
assert(-0.25 < c && c < +0.25);

auto d = rand!real.fabs;
assert(0.0L <= d && d < 1.0L);
import mir.math.common: fabs;
import mir.random.engine.xorshift;
auto gen = Xorshift(1);

auto a = gen.rand!float;
assert(-1 < a && a < +1);

auto b = gen.rand!double(4);
assert(-16 < b && b < +16);

auto c = gen.rand!double(-2);
assert(-0.25 < c && c < +0.25);

auto d = gen.rand!real.fabs;
assert(0.0L <= d && d < 1.0L);

Subnormal numbers

import mir.random.engine.xorshift;
auto gen = Xorshift(1);
auto x = gen.rand!double(double.min_exp-1);
assert(-double.min_normal < x && x < double.min_normal);

Meta