Skip to content

Instantly share code, notes, and snippets.

@halfdan
Created May 16, 2013 13:33
Show Gist options
  • Save halfdan/5591757 to your computer and use it in GitHub Desktop.
Save halfdan/5591757 to your computer and use it in GitHub Desktop.
Random Singleton in Java
public class RandomSingleton {
private static RandomSingleton instance;
private Random rnd;
private RandomSingleton() {
rnd = new Random();
}
public static RandomSingleton getInstance() {
if(instance == null) {
instance = new RandomSingleton();
}
return instance;
}
public double nextDouble() {
return rnd.nextDouble();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment