For shuffling two vectors in the same order, it's tempting to do something like
whatever_rng_type rng2(rng1);
std::shuffle(vec1.begin(), vec1.end(), rng1);
std::shuffle(vec2.begin(), vec2.end(), rng2);
where identical RNG states are used for the two shuffles. However, I don't see any requirement that these shuffles actually produce the same order in the standard draft I checked.
std::shuffle
must use the provided RNG as its source of randomness, but the implementation might also do something like take a different code path for different element sizes. Maybe an implementation might use AVX512 gather/scatter instructions for some types and a generic, non-vectorized code path for others, and that could affect the result ordering.
Is performing two shuffles with the same seed actually a safe way to get the same order? Is there something I missed in a later standard version, or a defect report or something?
Aucun commentaire:
Enregistrer un commentaire