Random chest, search for parameters

Hello everyone I'm making a roulette wheel for a training project. So, here I have a case with a price in 59, it contains items:

1 — 10 
2 — 30
3 — 50
4 — 60
5 — 80
6 — 100
7 — 140
8 — 200
9 — 250
10 — 400
11 — 600
12 — 1000
13 — 1500
14 — 2500 

How do I find the relationship between the item price, the case price, and the number of items and correctly distribute the drop chance for each item? I tried to play with the numbers and make some formula, but I do not get it and I do not know how to correctly calculate the percentage of each drop the price of the item depended on its price and on the price of the case.

Author: zcorvid, 2019-12-02

2 answers

Analysis of the problem from the point of view of probability theory.

There is a case, when you open it, one of the items 1..N (in your case, N = 14) accidentally falls out. Denote the price of the item c1, ... , cN, denote the probability of loss p1, ... , pN, p1 + ... + pN = 1.

The values of the items ck are known, we need to find the probabilities pk (for a given total case value, we denote this value by V).

Let's calculate the mathematical expectation of the price of the item that we get from case, it's easy:

EV := E{cost} = p1*c1 + ... + pN*cN

We need to ensure that the mathematical expectation of the price does not exceed the price of the case (otherwise, on average, the player will receive more from opening the cases than he paid for them, which is unprofitable for the game). Hence we get the condition:

EV <= V

We will assume that we are honest, and we will put equality above, that is, it will mean that the game has neither profit nor loss from the sale of cases (if you want, after the calculations, you can take the price V more than the calculated one, and the game will have profit, or less, then the players will have a profit).

We have the equation:

V = p1*c1 + ... + pN*cN

It does not have an unambiguous solution. Therefore, we will add additional requirements. Let's say we have 2 items, one is 2 times more expensive than the other, then it would be logical if the more expensive one would fall out 2 times less often than the cheaper one, that is, the cheaper one should fall out with a probability of 2/3, and the expensive one with a probability of 1/3. Hence, the logical conclusion is that the probabilities should be inversely proportional to the value of the items:

p_i = K * (1/c_i)

Adding a condition for normalizing probabilities:

1 = p1 + ... + pN = K * [(1/c1) + ... + (1/cN)]

From:

K = 1 / [(1/c1) + ... + (1/cN)]

The average harmonic value of the items.

Note that these conditions have already fully determined the probabilities, and from the equation above we can calculate the value of the case price V, which must be assigned so that there are no profits or losses. This means that it is generally impossible to choose the price V in advance.

Solve this problem you can partially add an item of zero value with probability p0 and price c0 = 0, then the coefficient K is determined from the equation of the coincidence of the mathematical expectation of the case price with the real price V = EV:

V = p1*c1 + ... + pN*cN
V = K*N
K = V/N

Now we sum up the probabilities p_i = K*(1/c_i) = V/(N*c_i):

p1 + ... + pN = (V/N) * ( (1/c1) + ... + (1/cN) )

And this sum should not exceed one, so that it can be supplemented with a non-negative probability `p0, which will be responsible for the fallout of conditional game garbage, then there is:

(V/N) * ( (1/c1) + ... + (1/cN) ) < 1

Where do we get the limit on the allowed pre-set price of the case V:

V <= N * (1 / ( (1/c1) + ... + (1/cN) ) )

And then

p0 = 1 - (V/N) * ( (1/c1) + ... + (1/cN) )

Conclusions and formulas.

  1. If the values of the items in the case are set in advance, then the price of the case V and the probability of dropping items p_i can be determined by the formulas:

    K   = 1 / [(1/c1) + ... + (1/cN)]
    V   = N*K
    p_i = K * (1/c_i)
    
  2. If the price of the case V is set in advance, then you should enter the probability p0 of an item falling out that does not represent game values, and probabilities will be determined by the following formulas:

    K   = V/N
    p_i = K * (1/c_i)
    p0  = 1 - (V/N) * ( (1/c1) + ... + (1/cN) )
    

    And this is possible only if the inequality is satisfied:

    V <= N * (1 / ( (1/c1) + ... + (1/cN) ) )
    
 4
Author: zcorvid, 2019-12-04 11:20:56

Perhaps it is worth making a kind of "value system", that is, to understand how much an expensive thing costs in the equivalent of a cheap one, compare everything with each other, and run a randomize. Next, you can try to implement something like this:

import random

  #Тут я просто написал рандомные числа, 
  #вам придётся самому просчитывать нужный шанс выпадения:
  #специальным алгоритмом, или "на бумажке" 
Variant = [50, 90, 120, 140, 150, 155, ...] 

a = random.randint(1, 150)
for i in range(len(Variant)):
    if a <= Variant[i]:
        print('Вам выпал предмет:' + str(i + 1))
        break

However, the list can be replaced with a dictionary ( {1: 50, 2: 90, ...}

 0
Author: Виктор Шевяков, 2019-12-03 05:05:29