https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80137

--- Comment #1 from John Salmon <john.salmon at deshaw dot com> ---
The misbehavior is observable by comparing an rng that is invoked directly with
one that is invoked via generate_canonical.

drdws0134$ cat skippy.cpp
#include <iostream>
#include <random>

int main()
{
    std::mt19937 rng;

    std::seed_seq sequence{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    rng.seed(sequence);
    rng.discard(12 * 629143);
    std::mt19937 rng2{rng};

    for(int i=0; i<20; ++i)
    {
        // mt19937 produces more than 23 bits per invocation, so
        // generate_canonical should invoke rng once.
        (void)std::generate_canonical<float, 23>(rng);
        // invoke rng2 once as well
        (void)rng2();
        // they should still be in sync
        if( rng2 != rng )
        {
            std::cout << "Bug at 12* 629143 + " << i << "!\n";
            return 1;
        }
    }

    return 0;
}
drdws0134$ g++ -Wall -std=c++11 skippy.cpp
drdws0134$ ./a.out
Bug at 12* 629143 + 6!



drdws0134$ drdws0134$ g++ --version
g++ (GCC) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

drdws0134$

Reply via email to