This could be an easy question and in fact, this is simple. But just wondering what's the proper algorithm for lucky draw chances?

Let's say in every new deposit amount of X get a no of chances of Y. Providing X = $1000, Y = 1

If there's a customer A credited $10000, he got 10 chances in this month.

If there's a customer B credited $2000, he got 2 chances in this month.

If there's a customer C credited $100, he got 0 chances in this month.

If there's a customer D credited $3500, he got 3 chances in this month.

By end of this month, how do I use a proper algorithm to pick a lucky draw winner? That's to pick a winner among this 15 chances.

One of the approaches is to create multiple chances in a temp table, and then random a position to pick the winner. But my question is what if the total no of chances is a very big number? Will the process of populating this temp table become slow?

Thank you.

In terms of an algorithm, I would be inclined to model 'raffle tickets':

Customer A gets tickets 1 to 10 inclusive

Customer B gets tickets 1 to 12 inclusive

Customer C gets no tickets

Customer D gets tickets 13 to 15 inclusive

I would then generate a random integer from 1 to 15 inclusive, and determine the winner from that.

Generating the table of tickets would be done throughout the month (or whatever period each 'draw' is over), so no noticeable load as you go, and the output is nothing more than a table of numbers and the name of the 'holder' of that ticket, which is appended to after each transaction is processed so very small.

After you have the winning number, you lookup that number in the table, and get the winner - no significant load there either.

Alan.