Here is a thread safe implementation of a RandomEngine based on the JDK sampler. This implementation is thread safe and better than the RandomCMWC (at least in the MCMC sampler that I'm running).
~~~~
import java.util.concurrent.ThreadLocalRandom;
import jdistlib.rng.RandomEngine;
public class JDKRandomEngine extends RandomEngine {
@Override public double nextGaussian() { return ThreadLocalRandom.current().nextGaussian(); } @Override public double nextDouble() { return ThreadLocalRandom.current().nextGaussian(); } @Override public float nextFloat() { return ThreadLocalRandom.current().nextFloat(); } @Override public int nextInt() { return ThreadLocalRandom.current().nextInt(); } @Override public int nextInt(int n) { return ThreadLocalRandom.current().nextInt(n); } @Override public long nextLong() { return ThreadLocalRandom.current().nextLong(); } @Override public long nextLong(long l) { return ThreadLocalRandom.current().nextLong(l); } @Override public RandomEngine clone() { return new JDKRandomEngine(); }
}
Anonymous
A few questions:
Thanks!
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
Good point, better is a bad word.
Cheers!
Apologies for rather late reply, but I've been very busy. Further questions.
Comment on #3: I'm not exactly sure how sharing one randomizer instance could prevent parallel problems, say, a race condition. But I guess in Lehmer's algorithm, it doesn't matter.
All in all, I am inclined to not include this code into the library. But I suppose other people could refer to this implementation if it suits their needs.