-3

I want to create a program in Python 3.5.2 that picks a random winner, but particitpants can have higher luck that others based on what they pay. How can i do that?

Edit: How could I make code that allows people to pay a fee and enter with their amount of dollars as their luck like a betting/raffle type of thing, there could be many people joining so it needs to be efficient.

Thanks in advance for all answers

Sketch of product for those more interested

I believe this question as not been asked before...

Community
  • 1
  • 1
  • You could mimic a real-life raffle with `random.choice` where some entrants have more "tickets" (i.e. elements in the list) than others – Patrick Haugh Nov 29 '16 at 17:52
  • Yeah, just partition the RNG output range between the players in the right proportions. – Useless Nov 29 '16 at 17:53

2 Answers2

0

Just adding the same person more than once?

Say: Tom put in 2 dollars, So did Matt but Scott only put one.

import random

participants = ['Tom', 'Tom', 'Matt', 'Matt', 'Scott']
print(random.choice(participants))
foxtdev
  • 161
  • 1
  • 15
0

There really isn't any question here, but if you are looking for some guidance, you could do this like LMGN stated:

You could have a collection that would add one entry per $1 added, so the person who adds $10 would get 10 entries. So if you had 3 players, player A added $1, player B added $3, and player C added $10, then the collection (like an array, a list, or something along those lines) would look something like this: {A,B,B,B,C,C,C,C,C,C,C,C,C,C} and then you just pick a random slot within the array. There are several genetic algorithms that use this method, and it works well instead of adding weights to each player.

Make sure you are careful that you make sure your random number is dynamic based on the number of entries into the "pool", that way you can have different amounts in the pool each game.

BrianH
  • 16
  • 2