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: unassig...@gcc.gnu.org
        ReportedBy: spoon.reloa...@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.

Reply via email to