android - How to randomly choose between two choices -
let's have choices , button randomly picks 1 of choises:
- i android
- i ios
how randomly pick answer using button?
you can in button
's onclick()
method
:
random rand=new random() int x = rand.nextint(2); if(x == 0) // choose answer 1 else // choose answer 2
you can use math
library too:
int x = (math.random() < 0.5) ? 0:1; if(x == 0) // choose answer 1 else // choose answer 2
Comments
Post a Comment