Linked Questions

3 votes
1 answer
3k views

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 ...
Qiao's user avatar
  • 17.1k
0 votes
1 answer
1k views

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 ...
user1683885's user avatar
0 votes
0 answers
722 views

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
user12578945's user avatar
2 votes
0 answers
40 views

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 ...
Vader's user avatar
  • 6,796
0 votes
0 answers
43 views

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 ...
Ian's user avatar
  • 153
0 votes
0 answers
20 views

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 ...
mus's user avatar
  • 3
418 votes
29 answers
415k views

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 ...
Colin's user avatar
  • 10.9k
81 votes
14 answers
42k views

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 ...
nimcap's user avatar
  • 10.6k
81 votes
14 answers
72k views

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 ...
Mikulas Dite's user avatar
  • 7,951
40 votes
6 answers
54k views

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, ...
Roughmar's user avatar
  • 425
50 votes
4 answers
9k views

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. ...
krlmlr's user avatar
  • 25.6k
7 votes
9 answers
20k views

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 ...
braden.groom's user avatar
3 votes
5 answers
2k views

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 ...
willc2's user avatar
  • 39.8k
10 votes
3 answers
3k views

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 ...
rampion's user avatar
  • 89.5k
2 votes
7 answers
3k views

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 ...
Chaggster's user avatar
  • 2,531

15 30 50 per page