c++ - generate same random permutation on every computer -
i using random_shuffle
on sequence a
1000 times. want ensure on every computer final sequence same. might undesirable, still want achieve this. srand(x)
ensure ?
there 2 sources of differences in resulting shuffle: algorithm rand()
not specified, different implementations produce different sequences of numbers; , algorithm random_shuffle
not specified, so, again, different implementations produce different results, same sequence of pseudo-random numbers.
you can eliminate first problem using of random-number generators in c++11; they're specified in detail, including, specializations, requirement 10,000th value, great in debugging implementation. however, there's no analog shuffling. in particular, algorithm std::shuffle
not specified, won't give reproducible results. you'll have write own. that's not difficult (nowhere near difficult writing engine), little research; there lots of discussion out there start from.
Comments
Post a Comment