Is std::random_shuffle threadsafe? I presume not since the regular rand() is not threadsafe. If that is the case, how would I use rand_r with random_shuffle so that I can give each thread a unique seed. I’ve seen examples of using custom random generators with random_shuffle, but it is still unclear to me.
Thanks.
To use
rand_rwithstd::random_shuffle, you’ll need to write a (fairly trivial) wrapper. The random number generator you pass torandom_shuffleneeds to accept a parameter that specifies the range of numbers to be produced, whichrand_rdoes not.Your wrapper would look something like this:
You’d use it with
random_shufflesomething like: