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

Popular posts from this blog

hibernate - How to load global settings frequently used in application in Java -

python 3.x - Mapping specific letters onto a list of words -

objective c - Ownership modifiers with manual reference counting -