saturated random number generator
bound exponent (optional). boundExp must be less or equal to T.max_exp.
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).
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);