Discussion forum > Suggestions
Fix the Lottery
tiggy26668:
soooo, clearly if u have more tickets u have the higher chance of winning..... but out of curiosity how are the tickets stored? does it just use a random number generator and whoever has that number ticket lets say wins, or are the tickets stored in some sort of stack/list where the winner is the ticket at the index defined by the random number? more so, if they're stored in a list/stack is it being shuffled before all/each draw or at all? ya gotta keep in mind that random numbers in computers are "pseudo-random" or "kinda random" and do have a tendency to fall in certain ranges given the algorithm used... point being if u have a giant chunk of 100 tickets in one section of this list/stack it can in fact give u an unfair advantage and increase your chance of winning.
of course this is all here say as i do not know the inner workings of the lottery, just some thoughts.
*edit* i hate criticizing without any contribution so a way to make it more random...
pseudo-code, would shuffle the tickets a random number of times....
(click to show/hide)
def Shuffle(Tickets)
OldTickets = Tickets
NewTickets = []
rand = randint(0,9)
for n in range(0,rand)
while OldTickets
i = randint(0,OldTickets.length)
NewTickets.append(OldTickets)
OldTickets.pop(i)
OldTickets = NewTickets
return NewTickets
Chief149:
public class Lottery
{
private ArrayList<String> tickets; //the list that holds all the tickets purchased by the player
public Lottery()
{
tickets = new ArrayList<String>(); //don't worry about this part of the code if you don't understand it
}
public void ticketsBought(String playerName, int numTickets) //when a player does /lottery buy numTickets command
{
//add the player name to the ticket list for each ticket they bought
//if a player did /lottery buy 10 to buy 10 tickets, then their name is added to the ticket list 10 times
for(int a = 1, a <= numTickets, a++)
{
tickets.Add(playerName);
}
}
public void drawWinners()
{
//create a completely random number
int randomNumber = (int)(Math.random()*(tickets.count()-1));
//That random number will be the number on the list that is chosen starting with 0. So if the number 2 is
//randomly generated, then the system goes to item number 2 on the list.
String winner1 = tickets.get(randomNumber); //this is winner 1 randomly selected
tickets.remove(randomNumber); //remove the individual drawn ticket from the list
//repeat the above code to get winner2 and winner3
//print winners and other crap to the chat
//award players with their money
}
}
That's how it works.
ViperZeroOne:
That looks completely random to me... I don't see how you could push the randomizer to be even more random than that.
ivy2112:
I won the lottery like cazual
if u look my signature
The prize pool was 5450$
i bhought ( by accididnt ) 645 tickets ( i wanted to buy 64 tickets )
I had ~ 93% of the prize pool tickets
i had a big chance to win as viper already said
ViperZeroOne:
--- Quote from: ivy2112 on July 21, 2012, 06:30:53 pm ---I won the lottery like cazual
if u look my signature
The prize pool was 5450$
i bhought ( by accididnt ) 645 tickets ( i wanted to buy 64 tickets )
I had ~ 93% of the prize pool tickets
i had a big chance to win as viper already said
--- End quote ---
Exactly, with a 93% chance on ALL 3 DRAWS you're pretty much guaranteed to win them all. Unless one of the other players has a horseshoe up their *cough*....
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version