The standard Random class should be enough, just make sure you use a unique seed everyday (say, a hash from every purchase data). Using time as seed (calling the Random
constructor without parameter) could be bad if your app is always started in the exact same time everyday.
The standard .NET library is good enough for statistical process. If you think you need stronger version, use the standard RNGCrypto library
from .NET. Unless you got thousands of buyer everyday, I don't think you really need the crypto version. Don't implement an algorithm yourself. There's a reason people use standardized random library, because it's already tested against statistical requirement
for randomness.
Uhm... if you need to pick several lucky customers with equal probability, simply put them on a List, generate an integer between 0 and the List length. The integer you get is the first lucky customer, store it somewhere, remove it from the list, rinse
and repeat for the next lucky customer. 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, useFitness
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
Sincerely,
Mahad Bin Mukhtar Remember to Mark the replies as Answers
The easiest day was 'yesterday'.
MCP, MCSD
For .NET TECH Blog
Marked as answer by Qi Wu - MSFT on May 15, 2012 03:15 PM
itman1981
Member
281 Points
376 Posts
balloting software (Lucky Draw ) sample needed
May 03, 2012 05:27 AM|LINK
Hello
I am looking for a balloting software (Lucky Draw )kind of. any help
AidyF
Star
9184 Points
1570 Posts
Re: balloting software (Lucky Draw ) sample needed
May 03, 2012 09:22 AM|LINK
Random r = new Random(); int i = r.Next(1, 11); if (i == 3) Literal1.Text = "You won!"; else Literal1.Text = "You lost.";itman1981
Member
281 Points
376 Posts
Re: balloting software (Lucky Draw ) sample needed
May 03, 2012 10:36 AM|LINK
Hello
basically I am using my employee code which has following formate.
MEM001 ...... MEM100 (Employee code)
THM500... THM700 (Employee code)
KEP200....KEP5000 (Employee code)
I have select from the above employee code ...
itman1981
Member
281 Points
376 Posts
Re: balloting software (Lucky Draw ) sample needed
May 03, 2012 10:36 AM|LINK
Hello
basically I am using my employee code which has following formate.
MEM001 ...... MEM100 (Employee code)
THM500... THM700 (Employee code)
KEP200....KEP5000 (Employee code)
I have select from the above employee code ...
MahadTECH
Star
8976 Points
1659 Posts
Re: balloting software (Lucky Draw ) sample needed
May 03, 2012 10:44 AM|LINK
Mahad Bin Mukhtar
Remember to Mark the replies as Answers
The easiest day was 'yesterday'.
MCP, MCSD
For .NET TECH Blog