-
-
Notifications
You must be signed in to change notification settings - Fork 741
Add seed(InputRange) overload to MersenneTwisterEngine #627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Maybe add the number of elements required to the error message and documentation? |
Also, you might want to add a note to the single integer overload, describing its limitations. |
The the number of elements required is not fixed. It's 624 for Mt19937 but it seems it can be any value for MersenneTwisterEngine. But I added a basic description to the docs. |
@@ -559,8 +559,11 @@ Parameter for the generator. | |||
|
|||
/** | |||
Seeds a MersenneTwisterEngine object. | |||
Note: | |||
This seed function gives 2^32 starting points. To allow the RNG to be started in any one of its | |||
2^19,937 internal states use the seed overload taking an InputRange. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2^19937 (-1) is only the period for Mt19937
, not for MersenneTwisterEngine
in general, right?
Yes, you're right. Removed the 2^19937 note. |
*/ | ||
void seed(T)(T range) if(isInputRange!T && is(Unqual!(ElementType!T) == UIntType)) | ||
{ | ||
int j; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
j
is used for indexing mt
and comparing against n
(which is a size_t
), so it should be size_t
, not int
.
@jmdavis OK, implemented your suggested changes. rndGen is also using the new seed overload now. However, I had to slightly change isSeedable as well. Without that change, it's not possible to use isSeedable for the new seed overload. |
Yes I should probably do that. Although adding the guarantee about Rng.front was wrong in the first place, but I didn't know that RNGs could be seeded with other types (I implemented isSeedable). |
map doesn't work in CTFE yet. I think we can just leave that as is, as long as rndGen uses the new seed method and we document the problems with the old seed overload. |
If there's really no relation between the type of |
OK, I removed the check again. It doesn't really make sense and user code should always check isRandomRNG(Type, frontType) and isSeedable(SeedType). |
Add seed(InputRange) overload to MersenneTwisterEngine
Merged. |
Adds a new seed overload as discussed here: http://forum.dlang.org/thread/jr0luj$1ctj$1@digitalmars.com