samedi 22 février 2020

Shuffle vector in C++14, C++17 [duplicate]

I am trying to shuffle my vector, but I am struggling to get it to work. I tried to look for answers online, but many answers seem to use a deprecated function std::random_shuffle. So far, my code looks like:

int main() {
    srand(time(NULL));

    vector<int> vec{1, 2, 3, 4, 5, 6};

    shuffle(vec.begin(), vec.end(), rand);

    return 0;
}

Could anyone tell me a concise and correct way to shuffle my vector?




Aucun commentaire:

Enregistrer un commentaire