Linked Questions
26 questions linked to/from Select k random elements from a list whose elements have weights
3 votes
3 answers
354 views
Iterating over the result of a member function
I have code that creates several object instances (each instance having a fitness value, among other things) from which I want to sample N unique objects using weighted selection based on their ...
0 votes
3 answers
3k views
Assigning probabilities to items in python
I understand the question title is vague. My apologies. I have a hashmap that has the key:value <string>:<list of lists>. For a given list, each of the items in the list has a ...
1 vote
1 answer
647 views
Deterministically assign an id in a list of weighted buckets
I'm running n split tests on a website. I want to assign an evenly distributed integer user id to one of the n buckets, and deterministically so the same user always gets the same test. At this point,...
2 votes
1 answer
945 views
uniform generation of points on 3D box
I would like to generate random points on a 3D box defined by its (minx, miny, minz) and (maxx, maxy, maxz) corners. I was thinking of generating a random point inside of the box and then somehow ...
0 votes
1 answer
2k views
Retrieve random object from list based on probability
I have to retrieve a random object from a list based on the weights/probabilities of the objects. I've found different solutions to the problem, but I'd like to share another approach to know if it's ...
6 votes
2 answers
482 views
Constrained weighted choice
I have a weighted choice algorithm that works, but I'd like to improve it in two aspects (in order of importance): Guarantee that a minimum number from each possible choice is chosen. Reduce ...
2 votes
8 answers
419 views
ideas for algorithm? sorting a list randomly with emphasis on variety
I have a table of items with [ID, ATTR1, ATTR2, ATTR3]. I'd like to select about half of the items, but try to get a random result set that is NOT clustered. In other words, there's a fairly even ...
1 vote
4 answers
218 views
Looping a set of if/else statements until a list variable has three unique values in Python 3
Trying to make this section of python code repeat until it gets three different results. This isn't the actual code, just a simplified version that does the same thing. roll = random.randint(1,100) ...
1 vote
1 answer
337 views
Random from Python Dict with lowest values as priority [duplicate]
Couldn't find this on Google so if anyone can help. I have a dict like this: {8: 0, 5: 0, 6: 1, 4: 2, 7: 3, 9: 2, 11: 1, 10: 3} Now I need to take 3 keys out of this dict randomly but also, here is ...
2 votes
0 answers
421 views
Sampling without replacement with unequal probabilites -- linear run time possible?
In search for a faster weighted sampling without replacement, the following question came up: Is there an algorithm that implements random sampling without replacement with unequal selection ...
2 votes
2 answers
199 views
Return random item by its weight, advanced level
There are many typical questions like https://softwareengineering.stackexchange.com/questions/150616/return-random-list-item-by-its-weight Imagine more advanced problem. You have N sources of pair (...