Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lottery system pot division

I making a lottery system in my web-based application, so it is in JavaScript, but my problem is more mathematical so feel free to write snippets in other language.

I want to distribute the lottery pot over winners in a natural feeling way, example:

var pot = 1000;
var tickets = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
tickets = shuffleArray(tickets); //shuffle tickets for winners
//first half wins something (2 should be changeable)
var winners_count = Math.ceil(tickets.length / 2);

In this scenario i need a way to divide the whole pot over the 10 winners where first place gets the most and last (10th) get fewest.

for(var i=0; i<winners_count; i++){
    var ticket = tickets[i];
    //formula to determine percentage of pot to gain needed.
}

example outcome: (just to show you where it needs to go, not actual match)

1 - 22%
2 - 18%
3 - 14%
4 - 12%
5 - 10%
6 - 8%
7 - 7%
8 - 5%
9 - 3%
10 - 1%

I am quite bad at mathematics and some pointers and/or code snippets would help me a lot in solving this.

EDIT

Solution from Fabien Roualdes: http://jsfiddle.net/LB8YU/1/

like image 915
MakuraYami Avatar asked Dec 06 '25 05:12

MakuraYami


1 Answers

I propose you to use an exponential distribution:

for(i=0 ; i<nrWinners ; i++){
    value = exp(-lambda*i);
    distribution[i] = value;
    sum += value;
}
for(i=0 ; i<nrWinners ; i++){
    distribution[i] /= sum;  
}

Lambda is a positive parameter which will permit you to choose the shape of the distribution:

  • If lambda is high the first winners will have a big part of the pot;
  • On the contrary, the smaller lambda is, the more the distribution will aim towards a fair division of the pot.

I hope it will help you!

EDIT: When I say lambda is high, it is already high if it is equal to 1 for 5 winners.

like image 143
Fabien Roualdes Avatar answered Dec 07 '25 18:12

Fabien Roualdes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!