int randomInt(int range) {
/* returns random integer in range [0,@range] */
Double random = new Double(Math.random()*range);
return random.intValue();
}
I use it to change my movement randomly across a switch statement ...
Pretty foolish :)
static Random rand = new Random();
...
... //Wherever you need a random integer:
randomInt = rand.nextInt(range);
-- PEZ
Interesting! I'll check the difference in codesize and memory. Clearer it is, indeed. That's what i get for being a beginner :P -- Qetu
Hmm, saved 4 bytes. I suppose the memory difference is negligible, so thanks!! -- Qetu
And with a Random object instantiated you have access to cool methods like nextGaussian() too. -- PEZ