D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3739 - Coding errors in LinearCongruentialEngine
Summary: Coding errors in LinearCongruentialEngine
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Linux
: P2 normal
Assignee: Andrei Alexandrescu
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2010-01-24 09:12 UTC by Witold Baryluk
Modified: 2015-06-09 01:27 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Witold Baryluk 2010-01-24 09:12:47 UTC
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 Andrei Alexandrescu 2010-01-24 09:25:41 UTC
Makes sense. I operated the changes and will commit soon.
Comment 2 Witold Baryluk 2010-01-31 09:19:31 UTC
Fixed in DMD 2.040