lundi 27 juin 2016

Does `std::shuffle` guarantees same order with same seed on different vectors?

I have two vectors with the same number of elements, but their types have completely different sizes. I need to shuffle them so that both have the exact same order after shuffling (each element in one vector is related each element in the other). The way I found to do it was:

// sizeof(a[0]) != sizeof(b[0])
// a.size() == b.size()
{
    std::mt19937 g(same_seed);
    std::shuffle(a.begin(), a.end(), g);
}
{
    std::mt19937 g(same_seed);
    std::shuffle(b.begin(), b.end(), g);
}

Can I rest assured that both vectors will be shuffled the same way? Is this implementation dependent? Do I have such guarantee from std::shuffle specification?

Aucun commentaire:

Enregistrer un commentaire