B
B
br1an2015-07-01 05:44:40
Mathematics
br1an, 2015-07-01 05:44:40

How to randomly select a winner based on their chance of winning?

Good afternoon, dear ones :)
There is such a task:
People make bets with items (items are valued by price, the price is usually a fractional number = 0.55, 34.22, etc.), after some time the winner should be selected randomly, BUT taking into account that chance of winning (the higher the bet, the greater the chance of winning).
Examples of such sites are csgojackpot.com, csgoup.ru
We implemented this algorithm like this https://gist.github.com/Riateche/3038910
But there are doubts, because very, very often people win with a small chance (you can, of course, justify , which they say is random)
Please tell me if we are using the correct algorithm (considering that the number is random - an integer, and the segments of the chances in the algorithm are fractional)? And are there better systems to randomly select a winner based on the chance of winning?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rsa97, 2015-07-01
@br1an

This is a classic algorithm. Visually, it can be represented as follows:
- Each bet is represented as a segment with a length equal to the bet.
- These segments are located on a straight line one after another without breaks.
- On the resulting segment, equal in length to the sum of all bets, a dot is thrown with equal probability.
- The bet on the segment of which this point hit wins.

M
Mrrl, 2015-07-01
@Mrl

It is better to take a fractional random number:
double r=frand()*total_chance_sum.
(I don’t know what frand() is called today - it should give a random number from 0 to 1). The condition current_sum <= r is not needed, it is always true.
If you want to increase the chances of those who made big bets, you can square these bets (i.e. if the prices are 0.5, 1, 2, then the chances of winning will be 1/21, 4/21, 16/21). I don't know if it's good.
In general, it is not very clear how
current_sum += items[i].chance works
if the amount is an integer and the rate is fractional. She does not swear at the loss of accuracy?

D
Danil Antoshkin, 2015-07-01
@TwerTrue

Well, the first thing I would do is simply collect the statistics of victories over the weeks, for example, and then judge whether the algorithm works normally or not.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question