-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Closed as not planned
Labels
invalidResolved as invalid, i.e. not a bugResolved as invalid, i.e. not a buglibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Description
The default random engine (std::minstd_rand0) produces a highly correlated initial distribution when varying the seeds (tested with clang 19.1.0 and seems to be the same for all prior versions):
#include <iostream>
#include <random>
int main(){
for(int seed = 0; seed < 100; seed++){
auto rng = std::default_random_engine(seed);
float value = std::uniform_real_distribution<float>(0, 1)(rng);
std::cout << value << "\n";
}
return 0;
}
Output
...
0.000101742
0.000109569
0.000117395
0.000125221
0.000133048
0.000140874
0.000148701
0.000156527
0.000164353
0.00017218
0.000180006
0.000187832
0.000195659
0.000203485
0.000211312
0.000219138
0.000226964
0.000234791
0.000242617
0.000250443
0.00025827
0.000266096
0.000273922
0.000281749
0.000289575
0.000297402
0.000305228
0.000313054
0.000320881
0.000328707
0.000336533
0.00034436
...
https://godbolt.org/z/x7jrEcaME
I think users would expect this to be uniformly distributed. GCC has the same issue but MSVC seems fine
Metadata
Metadata
Assignees
Labels
invalidResolved as invalid, i.e. not a bugResolved as invalid, i.e. not a buglibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.