Good afternoon, I can not figure out how to implement the probability of 0.7 output of one of the two options true or false. Help advice. :-)
|
2 answers
The question is not specific. In general, if you output true every 7 times in a row, true, and every 3 times - false, then the probability of occurrence of true - 0.7 will be achieved on large numbers of outputs. If you need a pseudo-random sequence, then
Random r = new Random (); while (true) { System.out.println(r.nextInt(10) < 7 ? "true" : "false"); }
- thanks for sure) - Kerins_Sataier
|
System.out.println(Math.random()<0.7);
|
random.Next(10) < 7
- AlexeyM