jeudi 11 mai 2017

shuffle() assigns the same number to all indices of a vector

I have a vector of numbers from 1 to 8. The code below makes every element "8".

  unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();

  shuffle (foo.begin(), foo.end(), std::default_random_engine(seed));

I do have srand(time(0)) at the beginning of my main function. I also have these headers:

#include <algorithm>
#include <ctime>
#include <random>
#include <chrono> 

I also tried both versions of random_shuffle(). Nothing seems to work.




Aucun commentaire:

Enregistrer un commentaire