By digging through sources you can find that this constructor uses Well19937c
random generator, which doesn't look thread-safe by itself at the first glance.
You can make it thread safe, by explicitly setting the number generator to SynchronizedRandomGenerator
which wraps any other random number generator (like Well19937c
or Mersenne Twister
). Note that by synchronizing access to random number generator with SynchronizedRandomGenerator
you'll lose all potential performance benefits and the 'parallel' version will be probably slower than a sequential one because of the synchronization. On the other hand, re-initializing the random distribution on every iteration in parallel will probably re-seed the PRNG multiple times with similar values based on current time, so your results will be skewed.
A very general rule of the thumb (and if I'm wrong here, please correct me) is that 99% of the time, unless explicitly stated otherwise, you should probably stick to sequential execution when doing anything that relies on random number generation, as usually PRNGs will store state that might get corrupted when calling them from multiple threads. And unless you're doing expensive computations afterwards, the synchronization (in case of thread-safe stateful PRNGs) will be a bottleneck.