Android - Selecting five random numbers with some probability -


i want select 5 random numbers probability.

my numbers: 2-5-6-9-14

probability: 2  -> %30 5  -> %20 6  -> %35 9  -> %10 14 -> %5 

i want go new activity if 3 numbers same.

not: maximum 3 numbers can same.

how can that?

you should try (can massively improved). idea generated number between 0 , 100 (representing 100%). , return number want based on probabilities:

public int random() {     random r = new random();     int n = r.nextint(100);      if (n < 30) // 30%         return 2;     if (n < (30 + 20)) // 20% (we exclude 30% above)         return 5;      if (n < (30 + 20 + 35))  // 35% (we exclude ones above)         return 6;      if (n < (30 + 20 + 35 + 10)) // 10% (30 + 20 + 35 previous probabilities)         return 9;      return 14;  } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -