[Issue 10550] Xorshift32 and Xorshift160 do not generate uniformly-distributed random numbers
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Jul 5 07:35:08 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10550
--- Comment #1 from Joseph Rushton Wakeling <joseph.wakeling at webdrake.net> 2013-07-05 07:35:07 PDT ---
The Xorshift32 non-uniformity can be fixed by correcting the update rule in
popFront(), from:
static if (bits == 32)
{
temp = seeds_[0] ^ (seeds_[0] << a);
temp = temp >> b;
seeds_[0] = temp ^ (temp << c);
}
to:
static if (bits == 32)
{
temp = seeds_[0] ^ (seeds_[0] << a);
temp = temp ^ (temp >> b);
seeds_[0] = temp ^ (temp << c);
}
See p.3 of http://www.jstatsoft.org/v08/i14/paper -- the current implementation
appears to be a typo when copying the first from the list of possible update
rules.
However, if this change is made, the Xorshift unittests fail for the checks
against the reference edition:
auto checking = [
[2463534242UL, 267649, 551450, 53765, 108832, 215250, 435468, 860211,
660133, 263375],
[362436069UL, 2113136921, 19051112, 3010520417, 951284840, 1213972223,
3173832558, 2611145638, 2515869689, 2245824891],
[521288629UL, 1950277231, 185954712, 1582725458, 3580567609,
2303633688, 2394948066, 4108622809, 1116800180, 3357585673],
[88675123UL, 3701687786, 458299110, 2500872618, 3633119408, 516391518,
2377269574, 2599949379, 717229868, 137866584],
[5783321UL, 93724048, 491642011, 136638118, 246438988, 238186808,
140181925, 533680092, 285770921, 462053907],
[0UL, 246875399, 3690007200, 1264581005, 3906711041, 1866187943,
2481925219, 2464530826, 1604040631, 3653403911]
];
alias TypeTuple!(Xorshift32, Xorshift64, Xorshift96, Xorshift128,
Xorshift160, Xorshift192) XorshiftTypes;
foreach (I, Type; XorshiftTypes)
{
Type rnd;
foreach (e; checking[I])
{
assert(rnd.front == e);
rnd.popFront();
}
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list