This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/51795] New: linear_congruential_engine doesn't work correctly
- From: "spoon.reloaded at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 09 Jan 2012 06:08:50 +0000
- Subject: [Bug libstdc++/51795] New: linear_congruential_engine doesn't work correctly
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51795
Bug #: 51795
Summary: linear_congruential_engine doesn't work correctly
Classification: Unclassified
Product: gcc
Version: 4.6.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: spoon.reloaded@gmail.com
I am trying to use a simple linear congruential engine from the random library
in C++11, and I am not getting what I expect.
#include <random>
#include <iostream>
int main() {
std::linear_congruential_engine<uint64_t, 1103515245, 12345, 2147483648>
foo(1103527590);
std::cout << foo() << std::endl; // prints 17294696140058308839
return 0;
}
This is obviously incorrect, as the result is far bigger than the modulus
(2147483648). I think the correct result should be (a * seed + c) mod m =
(1103515245 * 1103527590 + 12345) % 2147483648 = 377401575. Am I missing
something?
I am using the gcc and libstdc++ from Ubuntu oneiric, which is version 4.6.1. I
am using a 32-bit machine.