Skip to content

Conversation

WebDrake
Copy link
Contributor

@WebDrake WebDrake commented Jul 8, 2013

Corrects a number of apparent typos in George Marsaglia's original paper describing Xorshift RNGs, which result in severe deviations from uniformity in the random variates generated by Xorshift32 and Xorshift160.

The uniformity of the random variates produced has been verified casually but not yet systematically (e.g. with a high-quality random number test suite such as dieharder or TestU01).

The updated checking values have been generated from a corrected copy of Marsiglia's reference code, available from https://github.com/WebDrake/xorshift

WebDrake added 3 commits July 8, 2013 21:55
The original typo derives directly from George Marsaglia's paper
introducing the Xorshift RNGs.  The original checking values, derived
from that code, thus also reflect the typo.

A corrected version of the reference code is available from
https://github.com/WebDrake/xorshift/ and has been used to
generate the updated checking values.
The original typo derives directly from George Marsaglia's paper
introducing the Xorshift RNGs.  The original checking values, derived
from that code, thus also reflect the typo.

A corrected version of the reference code is available from
https://github.com/WebDrake/xorshift/ and has been used to
generate the updated checking values.
@ghost ghost assigned repeatedly Jul 9, 2013
repeatedly added a commit that referenced this pull request Jul 9, 2013
Fix Issue 10550 - Xorshift32 and Xorshift160 do not generate uniformly-distributed random numbers
@repeatedly repeatedly merged commit e1504f7 into dlang:master Jul 9, 2013
@repeatedly
Copy link
Contributor

Good catch!

{
static assert(false, "Xorshift supports only 32, 64, 96, 128, 160 or 192 bit versions. "
~ to!string(bits) ~ " is not supported.");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was already a static assert above that checked this:

    static assert(bits == 32 || bits == 64 || bits == 96 || bits == 128 || bits == 160 || bits == 192,
                  "Supporting bits are 32, 64, 96, 128, 160 and 192. " ~ to!string(bits) ~ " is not supported.");

While an explicit check for 192 is always clearer and makes the code more robust, the only diagnostic here worth throwing would be: "Phobos Error". Because if we hit that line, that's what it is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was already a static assert above that checked this

Yes. But we can add other bits version to this engine (e.g. 256 bits),
so I think each check is robust than old implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I deliberately added the double check. I thought it was important to be absolutely explicit about each possible value for the number of bits, and have a double-locked guarantee.

On that note, I just realized I missed the static if/else in popFront(). I'll push a separate fix for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants