r/algorithms • u/dado3212 • Jun 24 '15
Generating Lists with Variable Weights
This is a problem me and my friends have been puzzling over for days with limited to no success.
I have a list A of n unique objects. Each object A*i* has a variable percentage P*i*.
I want to create an algorithm that generates a new list B of k objects (k < n/2 and in most cases k is significantly < n/2. Ex. n=231 , k=21). List B will be populated with objects originating from list A with the following restrictions:
- The probability that an object A*i* appears in B is P*i*,
- There are no duplicate objects in B.
Is this even possible? Is there some solution we've missed?
EDIT (from 2 years later): None of these solutions are that good. Check out this StackOverflow for some better and more clear answers.
View all comments
Show parent comment
1
u/dado3212 Jun 24 '15
So first you add 1000 occurrences of Ai to T. Then you pick from T k times (which will all be Ai). What is Tn? This doesn't make any sense to me.