Created
May 16, 2013 13:33
-
-
Save halfdan/5591757 to your computer and use it in GitHub Desktop.
Random Singleton in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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