Linked Questions
28 questions linked to/from Weighted random selection with and without replacement
3 votes
1 answer
3k views
Get random element by given priority [duplicate]
Possible Duplicate: Weighted random selection with and without replacement I tired to make all decisions what to do next by myself. I want computer to do it. I only write things and give priority ...
0 votes
1 answer
1k views
Python: Select Item from Object List Based on Probability [duplicate]
Possible Duplicate: Weighted random selection with and without replacement I have a long object list of items. I want to randomly select an item from the list based on the probability. The list ...
0 votes
0 answers
722 views
How to get 5 random numbers with a certain probability? [duplicate]
How to write python with: Generate 5 random numbers with a certain probability from number 1-25(no repeat) Like generate 1 has 5%, 2 has 7% something like that
2 votes
0 answers
40 views
Python - manipulate odds [duplicate]
Introduction: I am trying to make a simple for in a row game using python. For one of my modules I need the computer to randomly choose a character to insert in the playing grid. I would like to have ...
0 votes
0 answers
43 views
What data structure is conducive to discrete sampling? [duplicate]
I have a collection of values and associated probabilities for each value (all positive, but far from being equal). I would like to sample from this distribution many times. One technically correct ...
0 votes
0 answers
20 views
Biased Random Choice from a class - python [duplicate]
I have for loop, and I need to modify it as follows: If we have CarTypes A or B: It will randomly choose methods which are AA, BB, CC, and DD. However, I want the choice to have a bias. So, I want the ...
418 votes
29 answers
415k views
A weighted version of random.choice
I needed to write a weighted version of random.choice (each element in the list has a different probability for being selected). This is what I came up with: def weightedChoice(choices): """Like ...
81 votes
14 answers
42k views
Select k random elements from a list whose elements have weights
Selecting without any weights (equal probabilities) is beautifully described here. I was wondering if there is a way to convert this approach to a weighted one. I am also interested in other ...
81 votes
14 answers
72k views
Weighted random selection from array [closed]
I would like to randomly select one element from an array, but each element has a known probability of selection. All chances together (within the array) sums to 1. What algorithm would you suggest ...
40 votes
6 answers
54k views
How can I make a random choice according to probabilities stored in a list (weighted random distribution)?
Given a list of probabilities like: P = [0.10, 0.25, 0.60, 0.05] (I can ensure that the sum of all the variables in P is always 1) How can I write a function that randomly returns a valid index, ...
50 votes
4 answers
9k views
Faster weighted sampling without replacement
This question led to a new R package: wrswoR R's default sampling without replacement using sample.int seems to require quadratic run time, e.g. when using weights drawn from a uniform distribution. ...
7 votes
9 answers
20k views
Python Random List Comprehension
I have a list similar to: [1 2 1 4 5 2 3 2 4 5 3 1 4 2] I want to create a list of x random elements from this list where none of the chosen elements are the same. The difficult part is that I would ...
3 votes
5 answers
2k views
How to choose randomly in a certain ratio
I want to choose randomly* between two alternatives with unequal probability. For instance, when the user presses a button, 25% of the time it would make sound A and 75% of the time, sound B. I can ...
10 votes
3 answers
3k views
Efficient algorithm to randomly select items with frequency
Given an array of n word-frequency pairs: [ (w0, f0), (w1, f1), ..., (wn-1, fn-1) ] where wi is a word, fi is an integer frequencey, and the sum of the frequencies ∑fi = m, I want to use a ...
2 votes
7 answers
3k views
How can I get weighted random selections from an array in Perl?
I need to random some elements from an array. I'm doing that by randomizing the index $array[int(rand(100))]. I want some of the elements to appear more often. How do I do it? I thought of a stupid ...