import std.array, std.range, std.random, std.stdio, std.traits; import mtclass; struct SimpleRandomRange(RNG = void) if(isUniformRNG!RNG || is(RNG == void)) { private real _min, _max, _u; static if(!is(RNG == void)) { private RNG _gen; this(real min, real max, RNG gen) { _min = min; _max = max; _gen = gen; _u = uniform(_min, _max, _gen); } typeof(this) save() @property { auto ret = typeof(this)(this); ret._gen = this._gen.save; return ret; } } else { this(real min, real max) { _min = min; _max = max; _u = uniform(_min, _max); } } this(typeof(this) source) { _min = source._min; _max = source._max; _u = source._u; static if (!is(RNG == void)) _gen = source._gen; } immutable bool empty = false; real front() @property pure nothrow const { return _u; } void popFront() { static if(is(RNG == void)) _u = uniform(_min, _max); else _u = uniform(_min, _max, _gen); } } auto simpleRandomRange()(real min, real max) { return SimpleRandomRange!void(min, max); } auto simpleRandomRange(RNG)(real min, real max, RNG gen) if(isUniformRNG!RNG) { return SimpleRandomRange!RNG(min, max, gen); } void main() { auto gen = new MtClass19937(unpredictableSeed); auto r = simpleRandomRange(0.0L, 1.0L, gen); auto t1 = r.take(5); auto s = r.save; auto t2 = s.take(5); writeln(t1); writeln(t2); auto t3 = r.take(5); auto t4 = s.take(5); writeln(t3); writeln(t4); }