I have had the question for a while now. How can you get a random number between x and y. Would you use the java Random() class, or does bukkit have one. Any help is appreciated.
Code: private static int getRandom(int min, int max) { return new java.util.Random().nextInt(max - min) + min; }
@gregthegeek Creating a new instance of Random is a heavy thing, so this would be better: Code:java private final Random rand = new Random(); private static int getRandom(int min, int max) { return rand.nextInt(max - min) + min;} Other than that see the docu of nextInt: http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Random.html#nextInt(int) - it will never give you the max value this way, so count max up: Code:java private static int getRandom(int min, int max) { return rand.nextInt(++max - min) + min;}
That's assuming he wants that value in there. He may not. And yes, I would've done it your way as well, but my way was more compact.