Constraints: a < b, a and b are finite numbers.
X ~ U[a, b$(RPAREN)
import mir.random.engine; import mir.math : nextDown; auto gen = Random(unpredictableSeed); auto rv = uniformVar(-8.0, 10); // [-8, 10) static assert(isRandomVariable!(typeof(rv))); auto x = rv(gen); // random variable assert(rv.min == -8.0); assert(rv.max == 10.0.nextDown);
import mir.random.engine; import mir.math : nextDown; auto gen = Random(unpredictableSeed); auto rv = UniformVariable!double(-8, 10); // [-8, 10) foreach(_; 0..1000) { auto x = rv(gen); assert(rv.min <= x && x <= rv.max); }
import mir.random.engine; import mir.math : nextDown; Random* gen = threadLocalPtr!Random; auto rv = UniformVariable!double(-8, 10); // [-8, 10) auto x = rv(gen); // random variable assert(rv.min == -8.0); assert(rv.max == 10.0.nextDown);
Uniform distribution (continuous).