C++ gcc 4.8.5和gcc 8.1.0之间的随机数生成差异

C++ gcc 4.8.5和gcc 8.1.0之间的随机数生成差异,c++,gcc,libstdc++,C++,Gcc,Libstdc++,使用gcc 4.8.5和gcc 8.1.0编译时,以下测试代码产生不同的结果: // test.cpp #include <algorithm> #include <random> #include <iostream> int main(){ std::mt19937_64 rand_gen(1); int n_combos = 5; std::vector<size_t> indices(n_c

使用gcc 4.8.5和gcc 8.1.0编译时,以下测试代码产生不同的结果:

// test.cpp
#include <algorithm>
#include <random>
#include <iostream>

int main(){
        std::mt19937_64 rand_gen(1);
        int n_combos = 5;
        std::vector<size_t> indices(n_combos);
        for (size_t i=0; i<n_combos; ++i)
                indices[i] = i;

        std::shuffle(indices.begin(), indices.end(), rand_gen);
        for(auto elem: indices)
                std::cout << elem << std::endl;
}
GCC 8.1.0:

[brock@localhost]$ /usr/bin/g++ --version
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)
Copyright (C) 2015 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.

[brock@localhost]$ /usr/bin/g++ -std=c++11 test.cpp -o printrandom.exe
[brock@localhost]$ ./printrandom.exe 
4, 3, 1, 0, 2,
[brock@localhost]$ g++ --version
g++ (GCC) 8.1.0
Copyright (C) 2018 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.

[brock@localhost]$ g++ -std=c++11 test.cpp -o printrandom.exe
[brock@localhost]$ ./printrandom.exe 
3, 0, 4, 2, 1, 

为什么它们对同一种子数生成器产生不同的结果和/或我如何找出它们不同的原因?我怀疑某个地方存在实现差异。

使用
-S
编译并检查发出的asm代码?您确定这是随机数生成而不是随机数生成吗?最好针对您的问题发布一篇量身定制的文章。我必须深入研究源代码以确认,因此只需将其作为注释发布:
std::shuffle
most like在其内部使用
std::uniform\u int\u分布来限制生成器的工作范围<代码>标准::统一整数分布需要给出特定的概率,但不需要给出总订单。如果GCC更改了它,那么这将解释不同的结果。我怀疑这是
std::shuffle
实现中的差异,您是否检查了两个版本之间生成的纯随机数序列?@NathanOliver这似乎是
std::shuffle
实现中的差异:vs。