B
B
bastian192018-09-18 23:11:28
Probability theory
bastian19, 2018-09-18 23:11:28

Set the probabilities for the occurrence of two numbers with an indication of the chance, how?

There is such a game:
N9wwA29dOTk.jpg
The user himself chooses the chance that he will guess. The greater the chance, the more likely it is to guess the button and get a win. And vice versa.
The question is that I don't know how to correctly write the probability in order to take into account the entered chance and, based on this, generate this or that button.
The "normal" probability won't work. Because at 80% you can win 20 times in a row, and this is no good.
That is why I created the question, because I don’t even know what can be thought up in this case.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2018-09-18
@bastian19

Generate a random from 1 to 100 and see if it's equal to or less than the specified probability.

$chance = 80;
if( mt_rand(1, 100) <= $chance) {
  // выиграл
} else {
  // проиграл
}

Example. For short, random from 1 to 10, and 80% probability. It is necessary that the number be less than or equal to 8.
Eight options are good: 1, 2, 3, 4, 5, 6, 7, 8 and two options are not good: 9, 10. Just 8:2 or 80:20.
Upd. Honest real randomness consists in the independence of the next result from the previous ones.
Since you have a task in a small window (on a small number of trials) to demonstrate a given distribution, you need to do something else: fill an array with the length of this window with wins/losses in the required proportion and issue one to the user one at a time. Those. store "state" between calls.
For 80% and a window of 20 items, fill it with 16 wins and 4 losses at random. And issue one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question