Linked Questions
26 questions linked to/from Select k random elements from a list whose elements have weights
0 votes
1 answer
3k views
Randomly selecting an object with a weighted probability in Python [duplicate]
Possible Duplicates: Random weighted choice Select random k elements from a list whose elements have weights Let's say I have a set of N objects, set = range(a,b) = [a,a+1,...b-2, b-1] To ...
220 votes
36 answers
180k views
Select N random elements from a List<T> in C#
I need a quick algorithm to select 5 random elements from a generic list. For example, I'd like to get 5 random elements from a List<string>.
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 ...
54 votes
9 answers
36k views
Weighted random selection with and without replacement
Recently I needed to do weighted random selection of elements from a list, both with and without replacement. While there are well known and good algorithms for unweighted selection, and some for ...
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, ...
21 votes
12 answers
22k views
Probability distribution in Python
I have a bunch of keys that each have an unlikeliness variable. I want to randomly choose one of these keys, yet I want it to be more unlikely for unlikely (key, values) to be chosen than a less ...
20 votes
4 answers
27k views
Weighted random numbers in MATLAB
How to randomly pick up N numbers from a vector a with weight assigned to each number? Let's say: a = 1:3; % possible numbers weight = [0.3 0.1 0.2]; % corresponding weights In this case probability ...
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. ...
18 votes
5 answers
13k views
Randomly selecting an element from a weighted list
I have a list of 100,000 objects. Every list element has a "weight" associated with it that is a positive int from 1 to N. What is the most efficient way to select a random element from the list? I ...
9 votes
7 answers
23k views
Weighted random sample in python
I'm looking for a reasonable definition of a function weighted_sample that does not return just one random index for a list of given weights (which would be something like def weighted_choice(weights,...
7 votes
4 answers
4k views
Select x random elements from a weighted list in C# (without replacement)
Update: my problem has been solved, I updated the code source in my question to match with Jason's answer. Note that rikitikitik answer is solving the issue of picking cards from a sample with ...
9 votes
1 answer
4k views
How to generate a random number from specified discrete distribution?
Lets say we have some discrete distribution with finite number of possible results, is it possible to generate a random number from this distribution faster than in O(logn), where n is number possible ...
1 vote
5 answers
4k views
Weighted sampling without replacement in Matlab
I have a population p of indices and corresponding weights in vector w. I want to get k samples from this population without replacement where the selection is done proportional to the weights in ...
3 votes
2 answers
2k views
Weighted random map
Suppose I have a big 2D array of values in the range [0,1] where 0 means "impossible" and 1 means "highly probable". How can I select a random set of points in this array according to the ...
3 votes
3 answers
1k views
Randomly selecting points in a plane, with a higher probability of selection given to closer points
I've got a problem I'm not too sure how to solve. I have a 2d space with several points in it. I also have a current point, which is one of the points in the space. I want to randomly select one of ...