I need to use a random function, but also have it repeating on different devices (PC / iOS / Android). I'm running this sample code, to shuffle a vector:
std::mt19937 generator(1337);
std::cout << "Your seed produced: " << generator() << std::endl;
std::vector<int> v = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
std::shuffle(v.begin(), v.end(), generator);
std::copy(v.begin(), v.end(), std::ostream_iterator<int>(std::cout, " "));
std::cout << "\n";
Output from two different PCs (windows):
Your seed produced: 1125387415
10 6 8 1 7 2 4 3 5 9
Output from iOS:
Your seed produced: 1125387415
9 1 4 6 7 8 5 3 10 2
Why am I getting different results? Is there another dependency relating to the OS itself? How is it possible to get this to work cross-platform?
Aucun commentaire:
Enregistrer un commentaire