P
P
PaffosONE2019-10-10 00:52:44
Algorithms
PaffosONE, 2019-10-10 00:52:44

Hello question, on the implementation of % in php?

Such a situation, I want to do something like OpenCase on the site, tell me how it is possible to give a % ratio in php, say
1. Object 10%
2. Object 50% to be random, taking into account% - chance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xmoonlight, 2019-10-10
@PaffosONE

1. Calculate the sum of the intervals-chances of all elements of the array and get the total range.
2. We take a random number on the entire range.
3. We look: in what interval-chance the dropped random number fell - we take that element.
Let us need the chances of letters to appear as follows:
A - 50%
B - 30%
C - the rest (20%)
0. Reduce by 10 ;)
1. Calculate: 5+3+2=
10 interval from 0 to 10.
3. Number from 0 to 5 - output A; from 5 to 8 - we output B, the remaining (8 to 10) is C.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question