Quote//create a completely random number
int randomNumber = (int)(Math.random()*(tickets.count()-1));
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*
it was beast

