I wanted to know how I could do this, because this code isn't working.
"ok" is supposed to be the most common, "bad" the second, and "good" should be rare, but they spawn at equal rates. I tried creating the integer a inside of the code and setting it to a random number right after, but it did the same thing. I'm currently setting b to 100.
public void spawnFood(int b) { if(a <= (b/2)+(b/4)) { addObject(ok, getWidth(), Greenfoot.getRandomNumber(getHeight())); a = Greenfoot.getRandomNumber(b); } else if(a > (b/2)+(b/4) && a <= ((b/2)+(b/4))+(((b/2)+(b/4))/4)) { addObject(bad, getWidth(), Greenfoot.getRandomNumber(getHeight())); a = Greenfoot.getRandomNumber(b); } else if(a > ((b/2)+(b/4))+(((b/2)+(b/4))/4) && a <= b) { addObject(good, getWidth(), Greenfoot.getRandomNumber(getHeight())); a = Greenfoot.getRandomNumber(b); } else { //Do Nothing } }