Created
June 12, 2012 09:08
-
-
Save jpf91/2916360 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///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)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment