From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4201 invoked by alias); 27 Jan 2012 21:22:34 -0000 Received: (qmail 4192 invoked by uid 22791); 27 Jan 2012 21:22:33 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 27 Jan 2012 21:22:21 +0000 From: "spoon.reloaded at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/51795] linear_congruential_engine doesn't work correctly Date: Fri, 27 Jan 2012 21:45:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: spoon.reloaded at gmail dot com X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: paolo.carlini at oracle dot com X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-01/txt/msg03204.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51795 --- Comment #19 from spoon.reloaded at gmail dot com 2012-01-27 21:21:40 UTC --- Paulo, in response to your suggestion to simply do multiplication and modulo in #7 and #8, I don't think that would work in general. The example I gave happened to have m = a power of 2 (namely 2^31), and so the truncation that we would get from integer overflow (whether by 2^32 if we use uint32_t or 2^64 if we use uint64_t) does not affect the result. However, if we choose any other number as a modulo (e.g. 2^31 - 1) and say we use uint32_t as the type, it will not work: (1103515245 * 1103527590 + 12345) % 2147483647 = 944465040 but in uint32_t arithmetic: (1103515245 * 1103527590 + 12345) % (1 << 32) % 2147483647 = 377401576 This is why I think we still need something like the Schrage's algorithm