Bug 3739 – Coding errors in LinearCongruentialEngine
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2010-01-24T09:12:00Z
Last change time
2015-06-09T01:27:22Z
Keywords
patch
Assigned to
andrei
Creator
witold.baryluk+d
Comments
Comment #0 by witold.baryluk+d — 2010-01-24T09:12:47Z
First at the end of class, wrong initalization.
- private UIntType _x = m ? a + c : (a + c) % m;
+ private UIntType _x = m ? (a + c) % m : (a + c);
};
Second in this method we can assome that if m is 0, and type is int, it was really 2^^32 (0 in int).
private static bool properLinearCongruentialParameters(ulong m,
ulong a, ulong c) {
+ static if (is(UIntType == uint)) {
+ if (m == 0) m = (1uL << 32);
+ }
// Bounds checking
if (m == 0 || a == 0 || a >= m || c >= m) return false;
// c and m are relatively prime
This problems are orthogonal to the my proposed optimalisations in bug3738.
Comment #1 by andrei — 2010-01-24T09:25:41Z
Makes sense. I operated the changes and will commit soon.
Comment #2 by witold.baryluk+d — 2010-01-31T09:19:31Z