Discussion forum > Suggestions

Fix the Lottery

<< < (4/7) > >>

tiggy26668:

--- Quote --- //create a completely random number
        int randomNumber = (int)(Math.random()*(tickets.count()-1));
--- End quote ---

hate to break it to you chief but that isn't random....

i wont even begin to address the complete loss of precision going on here due to using decimal values....

that whole argument aside think about the concept of multiplying a decimal between 0.0 and 1.0 inclusive times a positive integer.

first argument,
lets say we have 10^1 tickets in the lottery (never gonna happen), if the random decimal is anything equal to/smaller than .111->, (0.0, .111...) then 9*.(0.0-.111...) = 0.something, truncates to = 0
it follows (.111...2, .22...)*9 = 1.something, truncates to 1...etc all the way to (.88...9, .99....)*9 = 8.something, truncates to 8 leaving only 1.0 as the sole possible random number for the person who bought the last ticket to win, whereas the previous 9 tickets all had a seemingly equal chance to be drawn.

this thought process can be applied to larger amounts of tickets, simply move the decimal 1 place to the left for each power of 10

10^4 or 10,000 tickets
9,999*(0.0, .00011..) = 0.something
9,999*(.0001...2, .00022...) = 1.something, truncates to 1
.... etc
9,999*(.00088.....9, .00099...) = 8.something, truncates to 8
9,999*(.001...) = 9 *note only a single way to truncate to 9*

the difference in this situation is the problem repeats for every tenth ticket.

9,999*(.00188...9, .001999...) = 18.something, truncates to 18
9,999*(.002...) = 19.something, truncates to 19 *note only a single way to truncate to 19*
9,999*(.002...3) = (according to windows calc) 22.997 (WTF HAPPEND TO 20-21?!?!?!?!?!?!)

this pattern continues throughout the sequence effectively screwing over every tenth ticket as well as many others.

now if that argument isn't enough of a reason to rethink that way of generating a random number lets take into account a brief example of the "loss of precision" i wanted to avoid discussing.

lets take a simple expression, we have 10,000 tickets in the lottery and the random double is .001111,

do it on paper, 9,999*(.0001111) = .9999, truncates to 0 (perfect)

now plug it into your calculator that come standard with any windows machine

9,999*(.0001111) = 1.110889, truncates to 1 (WTF RAGE LOTTERY IS RIGGED OMFG!)

this isn't a specific situation, it reappears at specific intervals depending on the amount of bits used to store the double variable because in computer world when a decimal doesn't fit in 8 bits, the computer picks the closest number that does.

Now, with my long lecture said and done, i really hate criticizing without contributing....

in an effort to prevent problems such as these from occurring i would suggest using a random integer for your random index generation, then manipulate that number into a usable index because integer values are less prone to loss of precision, or more simply just use the nextint function and bypass it all together.

also i would suggest shuffling the list of names/tickets so that you don't end up with giant chunks of names taking advantage of the better ranges to be in, it would be an overall better mix-up/randomization as both the tickets and the index of winning tickets have been randomized

sincerely,
Tiggy

*Breathes*

caseyboy123:
Tiggy is right.
But for everyone who did not under stand that i will simplify.  Heres a scenario.  Xeadin purchases 4 tickets.  BigBadHenz purchases 3.  Nick Purchases 2 tickets. And i purchase 1.  So there are a total of 1o tickets.  each ticket is one-tenth of the total pot.  so each ticket has a ten percent chance of being chosen.  So there is a 40% chance that Xeadin will win. and a 60% chance that he wont.  So if we were to draw a ticket and put it back.  and repeat this ten times Xeadin would win 4 times while someone else would win the other 6 times.  This is according to probability. 

Now A new drawing situation.  Lets say we draw three times and each tim the ticket is removed.

caseyboy123:
wtf i wrote like a whole page and it didnt post :( it was beast

caseyboy123:
Alright im going to finish my post now.  So Xeadin has 8 tickets i have 1 and Henz has 1.  First draw Xeadin has an 80% chance of winning.  So When the computer draws Xeadin Will win.  The next Draw there are only nine tickets and Xeadin has 7 of them.  The Chance that xeadin will win is 77.7777777777777777777777777777777777777777777%  So When the computer picks one xeadin will win again. and now for the third draw Xeadin will have a 75% chance of winning. So when the Computer draws Xeadin will win again.  Now Xeadin has won all three picks.  This is because the loto is based on probability and stats.  If it was random it may be different.  But because a computer is based on satats and probability it does not draw randomely.  But this does not mean it is rigged.  So yes the loto is not random but it is not rigged.  so i hope that satisfies both sides.

Hell ya science:)

tiggy26668:

--- Quote from: caseyboy123 on July 22, 2012, 01:36:19 am ---Alright im going to finish my post now.  So Xeadin has 8 tickets i have 1 and Henz has 1.  First draw Xeadin has an 80% chance of winning.  So When the computer draws Xeadin Will win.  The next Draw there are only nine tickets and Xeadin has 7 of them.  The Chance that xeadin will win is 77.7777777777777777777777777777777777777777777%  So When the computer picks one xeadin will win again. and now for the third draw Xeadin will have a 75% chance of winning. So when the Computer draws Xeadin will win again.  Now Xeadin has won all three picks.  This is because the loto is based on probability and stats.  If it was random it may be different.  But because a computer is based on satats and probability it does not draw randomely.  But this does not mean it is rigged.  So yes the loto is not random but it is not rigged.  so i hope that satisfies both sides.

Hell ya science:)

--- End quote ---

well caseyboy, the point i was trying to get at was given that algorithm some numbers actually had a lower probability to be drawn and others were being skipped completely, that means some tickets could never be drawn and others have a lower chance regardless of the amount the person bought

*edit* that means it's rigged.....

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version