I need a 1 in a 100 chance of some functionality being called. Right now I am using the following code, but it’s being called more often than 1% of the time.
int randomItem = (int)(Math.random()*100);
if (randomItem >= 90 && randomItem <= 100)
{
// Do something ...
}
You’re adding the sprite when the random number is between 90 and 100. This makes a 10% chance. Just test if Math.random() is
< 0.01.