public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/51795] New: linear_congruential_engine doesn't work correctly
@ 2012-01-09  6:09 spoon.reloaded at gmail dot com
  2012-01-27  7:01 ` [Bug libstdc++/51795] " 3dw4rd at verizon dot net
                   ` (30 more replies)
  0 siblings, 31 replies; 32+ messages in thread
From: spoon.reloaded at gmail dot com @ 2012-01-09  6:09 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2012-04-29 23:39 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-09  6:09 [Bug libstdc++/51795] New: linear_congruential_engine doesn't work correctly spoon.reloaded at gmail dot com
2012-01-27  7:01 ` [Bug libstdc++/51795] " 3dw4rd at verizon dot net
2012-01-27 10:59 ` paolo.carlini at oracle dot com
2012-01-27 11:23 ` paolo.carlini at oracle dot com
2012-01-27 11:46 ` paolo.carlini at oracle dot com
2012-01-27 12:18 ` paolo.carlini at oracle dot com
2012-01-27 12:47 ` paolo.carlini at oracle dot com
2012-01-27 12:53 ` paolo.carlini at oracle dot com
2012-01-27 13:02 ` paolo.carlini at oracle dot com
2012-01-27 13:06 ` marc.glisse at normalesup dot org
2012-01-27 13:07 ` paolo.carlini at oracle dot com
2012-01-27 13:42 ` marc.glisse at normalesup dot org
2012-01-27 13:48 ` paolo.carlini at oracle dot com
2012-01-27 13:49 ` paolo.carlini at oracle dot com
2012-01-27 13:55 ` marc.glisse at normalesup dot org
2012-01-27 13:58 ` paolo.carlini at oracle dot com
2012-01-27 14:08 ` paolo.carlini at oracle dot com
2012-01-27 14:12 ` marc.glisse at normalesup dot org
2012-01-27 14:28 ` paolo.carlini at oracle dot com
2012-01-27 21:45 ` spoon.reloaded at gmail dot com
2012-01-27 21:50 ` spoon.reloaded at gmail dot com
2012-01-27 21:51 ` paolo.carlini at oracle dot com
2012-01-27 21:53 ` paolo.carlini at oracle dot com
2012-01-27 21:56 ` spoon.reloaded at gmail dot com
2012-01-27 22:32 ` paolo.carlini at oracle dot com
2012-01-27 23:08 ` marc.glisse at normalesup dot org
2012-01-28  0:34 ` paolo at gcc dot gnu.org
2012-01-28 11:34 ` paolo.carlini at oracle dot com
2012-01-30 16:26 ` paolo.carlini at oracle dot com
2012-02-01 11:12 ` paolo at gcc dot gnu.org
2012-04-29 23:37 ` paolo at gcc dot gnu.org
2012-04-29 23:39 ` paolo.carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).