that is the exact code then i have a switch for case 0: and case 1: it seems that the case 1: is coming out every time, i would like to have a 50/50 chance of 0 or 1 coming out is this the correct way or should i use 1.5 or how exactly does this work?
talka = (int)(Math.random() * 1);
switch(talka)
{
case 0:
{
talk.setAnimationListener(this);
talk.playtimes(1,24);
startService(new Intent(this, love1.class));
break;
}
case 1:
{
talk.setAnimationListener(this);
talk.playtimes(1,12);
startService(new Intent(this, love2.class));
break;
}
}
The problem has to do with the way the cast works.
In may test, Java was basically “trimming” the decimal result off and simply taking the “integer” component. However, if I rounded the result, I got it flipping between 0 and 1.
Have a play
It my simple test, I was getting around the 50/50 mark (+/-)
As pointed out by Hovercraft, better to use
java.util.Randomin this case.