Reputation: 103
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.
Upvotes: 0
Views: 181
Reputation: 2272
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:
The resulting list would be:
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.
Upvotes: 2