dimanche 11 juillet 2021

std::shuffle same result each start [duplicate]

std::shuffle returns same result each start of program, I don't understand what's wrong. Here is an example:

#include <vector>
#include <random>
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    vector<string> backgroundSongs = {
            "../music/Sound_04669.mp3",
            "../music/Sound_11084.mp3",
            "../music/Sound_17211.mp3"
    };

    //std::random_device rd;
    //std::default_random_engine rng(rd());

    shuffle(backgroundSongs.begin(), backgroundSongs.end(), std::mt19937(std::random_device()()));

    for (const auto& song : backgroundSongs)
        cout << song << " ";
    cout << endl;

    return 0;
}



Aucun commentaire:

Enregistrer un commentaire