I am working a e-commerce website (in asp.net & c#) where which I want to implement a ‘Lucky draw’ functionality.The control flow would be like this :- the users will be buying a particular product on a day and I need to select a user from those who have purchased that product as the luck draw winner for the day.
My initial thought on implementing the lucky draw was to use the Random functions provided by C#.And there are lots of thoughts came in to my mind like ..
- How effective it would be if I only use the random functions in c#?
- Would it be better if I implement any random number generation algorithms for this purpose ?
- Is there any algorithms available for random selections from a group?
I am open to your valuable comments and suggestions.
Thanks
Alex
If you need to give higher probability according to their purchase count, store the purchase details instead of the customer inside the List. If you need custom weight according to the purchase value, use Fitness proportion, in which you total all purchase value for the day, then give each customer a cumulative value from their purchase. eg, if there are total $350 sale on that day, the first customer buying $75 got 75, the second customer buying $20 got 95 (75+20), the third customer buying $10 got 105 (95+10), etc. Then, pick a random integer between 0 and total sale, and the lucky winner is the customer with the lowest value that is still higher than the resulting integer. Remove the first winner from the list (both their total and position), rinse and repeat for the next customer.