Hey fellas,
I’m using java.util.Random for lots of different things in my game (rolling dice, choosing different enemies, names, etc.). I have read that it is usually a good idea to use one source of random numbers (incase you want to save the seed for example as far as I understood).
In my “older” game I had a Dice.class that in which I used:
public static Random rnd = new Random();
// and called
{
Dice.rnd ...
}
// everywhere else
In my latest try (in which I really want to take my time and learn stuff properly instead of wanting to finish a game as fast as possible) I now switched to a singleton pattern:
public class RandomInstantiation
{
final private static Random instance = new Random();
private RandomInstantiation() {};
public static Random getInstance() {
return instance;
}
}
I’d love to know if this is a proper way to do this, as I’ve also read that usually singleton patterns aren’t encouraged… (whatever that means ???).