Skip to content

Linear congruential generator produces different values than gcc and msvc #33554

@llvmbot

Description

@llvmbot
Bugzilla Link 34206
Version 5.0
OS MacOS X
Attachments linear_congruential_engine test
Reporter LLVM Bugzilla Contributor
CC @mclow

Extended Description

To my understanding the C++ standard does not mandate the algorithms for random number distributions but it does mandate the algorithms for random number generators like linear_congruential_engine. So one should be able to generate consistent random values across all platforms/compilers.

However, i stumbled upon inconsistent values between various compilers and verified this observation with online compilers. I am not sure which compiler is right, but at least gcc and msvc agree on their results.

Please find attached a code snippet to reproduce the observed behavior.

I put this code snippet into Rextester:

http://rextester.com/l/cpp_online_compiler_gcc (g++ 5.4.0)
http://rextester.com/l/cpp_online_compiler_clang (clang 3.8.0)
http://rextester.com/l/cpp_online_compiler_visual (Microsoft 19.00.23506 for x86)

Output:

25214903928 206026503483683 245470556921330 (gcc)
25214903928 18444698300399350051 8295313034219953650 (clang)
25214903928 206026503483683 245470556921330 (msvc)

I also put this code snippet into a Compiler Explorer project. It illustrates that Clang 3.8 and Clang trunk produce exactly the same code/values.

https://godbolt.org/g/rBSjaS

A possibly somehow related issue:

#28213

Metadata

Metadata

Assignees

Labels

bugzillaIssues migrated from bugzillaconfirmedVerified by a second partylibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions