public
Created

  • Download Gist
gistfile1.d
D
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
///Seed using an InputRange
void seedRange(T)(T range) if(isInputRange!T && is(Unqual!(ElementType!T) == UIntType))
{
int j;
for(j = 0; j < n && !range.empty; ++j, range.popFront())
{
mt[j] = range.front;
}
 
mti = n;
if(range.empty && j < n)
throw new Exception("MersenneTwisterEngine.seedRange: Input range didn't provide enough"
" elements");
 
popFront();
}
 
unittest
{
Mt19937 gen;
//This is repeating one unpredictableSeed! Not a good idea in general, but OK for the unittest
bool thrown = false;
try
gen.seedRange(repeat(unpredictableSeed, 623));
catch(Exception)
thrown = true;
 
assert(thrown);
 
gen.seedRange(repeat(unpredictableSeed, 624));
//infinite Range
gen.seedRange(repeat(unpredictableSeed));
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.