Skip to content

Comment on C++ Seeding Surprises (2015)parent

Comments

Why not just run your tests with a fixed seed? e.g.

    std::mt19937 gen(42);
    std::uniform_int_distribution<> dist(1, 100);
    int random_number = dist(gen);

uniform_int_distribution differs between compilers/platforms! Don't use it if you don't want true randomness.

Thank you, that makes sense. I can see that being an issue for testing.

I wouldn't describe "pseudo-random sequences that differ between compilers/platforms/versions but are deterministic for a given toolchain" as "true randomness" but I understand the point.

I have confirmed that uniform_int_distribution gives different results on x86-64 clang (trunk) with libc++ [1] vs x86-64 clang (trunk) with libstdc++ [2].

[1]: https://godbolt.org/z/dd5YMs7zo

[2]: https://godbolt.org/z/8svGn7Exc

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.