0

I'm really sorry, I would search my question but I don't know how to word it correctly, I have a big problem with mental math and I've been trying to think of a solution. I'm trying to build a program for my guild that will add names to a list. This list has a parallel struct for each entry that holds the person's name and number of donations to a raffle.

I want to randomize through all the names and have the results positively influenced by the amount of donations people have put in. likes 1 or 1% increase in possibility * number of donations. I've done randomization before but I've never had to influence the odds slightly. help me please? I would post code but I don't have ANY randomization at the time. I can give you some other stuff though:

I made a struct to hold each user's entry:

    public struct pEntry
    {
        public string Name;
        public int Entries;
    }

I made a list to hold all the entries:

    public List<pEntry> lEntries = new List<pEntry>();

I want my randomization to be positively influenced by the number of entries(donations) they've made. This has no cap on how high it can go but if I need to maybe I can make it like.. 255.After it randomizes it will pick display a message saying that, that user has won and it will remove that entry from the list and pick a few more. This program will be used for multiple raffles and things like it but all use the same system.

6
  • 6
    Why not just have a list of strings; anyone who buys two tickets gets put on the list twice. If they buy three tickets, they get put on the list three times. Then just choose a random item from the list. After all, that's how it actually works with real paper tickets. Commented Apr 27, 2013 at 0:40
  • If you need something quick and dirty, you could fill add an entrant to a temp array for every entry they made. Then you could randomize the index for that collection. EDIT: @EricLippert beat me to it =) Commented Apr 27, 2013 at 0:40
  • 3
    Note also that if there is serious money on the line here then you should use a cryptographically secure source of randomness. The "random" numbers generated by Math.Random actually highly predictable; they are only pseudo-random. Commented Apr 27, 2013 at 0:44
  • Haha, you guys are great. Yea, I guess I was overcomplicating it, I'll try a unique UID as to avoid duplication. Thank you, I really appreciate it :) Commented Apr 27, 2013 at 0:50
  • The way the question is phrased sounds like everyone gets a base "chance" of winning (ie, a free ticket), and he wants to generate bonus chances based on size of donations but not have it so that someone that donates 10 units gets 11 chances (ie, 1 free ticket and 10 bonus tickets). But he will need to decide exactly how big a donation increases the chances to work out the math he needs. Commented Apr 27, 2013 at 0:52

1 Answer 1

2

You need to know how much donations increase the chance of winning. Does 1 = 1 more chance than someone that hasn't donated? Once you have a base and a bonus, you can just generate a "chart", see what your top number is, and generate a random number. After that, you can remove that person or reset their chances by whatever fraction you want, regenerate your chance list, and generate a new number.

For instance, if you want 1 donation unit to give 10% more chance for that person, then you could generate a list of all the guild, and each person gets 10 "lots" + 1 lot per donation unit. So if you had 3 people, where:

  • Ann gave 5 donation units
  • Tom gave 2 donation units
  • Bob didn't give any

The resulting list would be:

  1. Ann lot count: 10 (base) + 5 (donations) = 15 lots
  2. Tom lot count: 10 (base) + 2 (donations) = 12 lots
  3. Bob lot count: 10 (base) + 0 (no donations) = 10 lots

Then you generate a number between 1 and 37 (15 + 12 + 10) to determine the winner.

Figure out what each donation should improve their odds (increases in their lots) and then you can start building your ranges and generate your numbers.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.