How can I make a piece of code that will generate me my bitmaps by chance. I want a 50% chance for bitmap1, 50% for bitmap2 and 20% for bitmap3. Can I get some advice on how to do that?
I know how to do it for fifty-fifty:
Random r = new Random();
int randBall = r.nextInt(2);
if (randBall == 0) {
return Gball;
} else if (randBall == 1) {
return Bball;
}
But if I want to add one more ball with a 20% chance of spawning, I don’t know how to do that.
You can use the java Random.nextInt(int) method.
Call
nextInt(100);and use