All Questions
Tagged with probability math
390
questions
308
votes
23
answers
251k
views
Generate a random point within a circle (uniformly)
I need to generate a uniformly random point within a circle of radius R.
I realize that by just picking a uniformly random angle in the interval [0 ... 2π), and uniformly random radius in the ...
137
votes
7
answers
57k
views
Is it safe to assume a GUID will always be unique?
I know there is a minute possibility of a clash but if I generated a batch of 1000 GUIDs (for example), would it be safe to assume they're all unique to save testing each one?
Bonus question
An ...
79
votes
14
answers
41k
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 ...
74
votes
15
answers
7k
views
What is the probability that the array will remain the same?
This question has been asked in Microsoft interview. Very much curious to know why these people ask so strange questions on probability?
Given a rand(N), a random generator which generates random ...
54
votes
7
answers
306k
views
How to calculate mean, median, mode and range from a set of numbers
Are there any functions (as part of a math library) which will calculate mean, median, mode and range from a set of numbers.
30
votes
4
answers
9k
views
How to generate random numbers biased towards one value in a range?
Say, if I wanted to generate an unbiased random number between min and max, I'd do:
var rand = function(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
But what if I ...
26
votes
7
answers
13k
views
C puzzle: Make a fair coin from a biased coin
How can I determine the probability that a function would return 0 or 1 in the following case:
Let the function_A return 0 with
probability 40% and 1 with probability
60%. Generate a ...
26
votes
3
answers
21k
views
Fastest primality test
Could you suggest a fast, deterministic method that is usable in practice, for testing if a large number is prime or not?
Also, I would like to know how to use non-deterministic primality tests ...
25
votes
7
answers
39k
views
Generate random number with given probability matlab
I want to generate a random number with a given probability but I'm not sure how to:
I need a number between 1 and 3
num = ceil(rand*3);
but I need different values to have different probabilities ...
25
votes
1
answer
33k
views
Probability of hash collision
I am looking for some precise math on the likelihood of collisions for MD5, SHA1, and SHA256 based on the birthday paradox.
I am looking for something like a graph that says "If you have 10^8 ...
23
votes
5
answers
47k
views
Algorithm to generate Poisson and binomial random numbers?
i've been looking around, but i'm not sure how to do it.
i've found this page which, in the last paragraph, says:
A simple generator for random numbers taken from a Poisson distribution is obtained ...
22
votes
10
answers
4k
views
Representing continuous probability distributions
I have a problem involving a collection of continuous probability distribution functions, most of which are determined empirically (e.g. departure times, transit times). What I need is some way of ...
21
votes
5
answers
13k
views
permutation & combinations interview
This is a good one because it's so counter-intuitive:
Imagine an urn filled with balls, two-thirds of which are of one color and one-third of which are of another. One individual has drawn 5 balls ...
20
votes
7
answers
16k
views
What is the probability of guessing (matching) a Guid?
Just curious but what is the probability of matching a Guid?
Say a Guid from SQL server: 5AC7E650-CFC3-4534-803C-E7E5BBE29B3D
is it a factorial?: (36*32)! = (1152)!
discuss
=D
19
votes
6
answers
12k
views
Generating N numbers that sum to 1
Given an array of size n I want to generate random probabilities for each index such that Sigma(a[0]..a[n-1])=1
One possible result might be:
0 1 2 3 4
0.15 0.2 0.18 0.22 0.25
...
18
votes
10
answers
30k
views
How can I efficiently calculate the binomial cumulative distribution function?
Let's say that I know the probability of a "success" is P. I run the test N times, and I see S successes. The test is akin to tossing an unevenly weighted coin (perhaps heads is a success, tails is ...
18
votes
6
answers
8k
views
Nth Combination
Is there a direct way of getting the Nth combination of an ordered set of all combinations of nCr?
Example: I have four elements: [6, 4, 2, 1]. All the possible combinations by taking three at a time ...
17
votes
5
answers
11k
views
Generate random numbers distributed by Zipf
The Zipf probability distribution is often used to model file size distribution or item access distributions on items in P2P systems. e.g. "Web Caching and Zip like Distribution Evidence and ...
16
votes
4
answers
24k
views
Probability of 64bit Hash Code Collisions
The book Numerical Recipes offers a method to calculate 64bit hash codes in order to reduce the number of collisions.
The algorithm is shown at http://www.javamex.com/tutorials/collections/...
15
votes
2
answers
9k
views
Chance of a duplicate hash when using first 8 characters of SHA1
If I have an index of URLs, and ID them by the first 8 characters of a SHA1 hash, what is the probability of two different URLs having identical IDs?
15
votes
5
answers
4k
views
Estimating/forecasting download completion time
We've all poked fun at the 'X minutes remaining' dialog which seems to be too simplistic, but how can we improve it?
Effectively, the input is the set of download speeds up to the current time, and ...
12
votes
8
answers
2k
views
What is O value for naive random selection from finite set?
This question on getting random values from a finite set got me thinking...
It's fairly common for people to want to retrieve X unique values from a set of Y values. For example, I may want to ...
12
votes
6
answers
4k
views
How to generate correlated binary variables
I need to generate a series of N random binary variables with a given correlation function. Let x = {xi} be a series of binary variables (taking the value 0 or 1, i running from 1 to N). The marginal ...
11
votes
6
answers
3k
views
Adjust items chance to be selected from a list
I have a list of items. When I create the list each item has equal chance to be selected. But as an item is selected its chance goes down while the others chance goes up. If a new item is added ...
11
votes
3
answers
4k
views
Does an open-source poker-related math library exist? [closed]
I would like to develop a poker odds application that can give the probability of various game situations. Since the application will be mostly statistical analysis, I figured I would see if someone ...
10
votes
3
answers
8k
views
Generate a uniformly random point within an annulus (ring) [duplicate]
Possible Duplicate:
Create random number within an annulus
I would like to obtain a uniformly obtained random point within an annulus, that is, the area that lies inside a circle of radius R1, ...
9
votes
1
answer
8k
views
Probability of collision with truncated SHA-256 hash
I have a database-driven web application where the primary keys of all data rows are obfuscated as follows: SHA256(content type + primary key + secret), truncated to the first 8 characters. The ...
8
votes
7
answers
15k
views
generate random numbers within a range with different probabilities
How can i generate a random number between A = 1 and B = 10 where each number has a different probability?
Example: number / probability
1 - 20%
2 - 20%
3 - 10%
4 - 5%
5 - 5%
...and so on.
I'...
8
votes
4
answers
7k
views
Three colors triangles
I am trying to make a code for this problem:
(Source: https://www.codewars.com/kata/insane-coloured-triangles/train/c)
A coloured triangle is created from a row of colours, each of which is
...
8
votes
4
answers
5k
views
Discrete Probability Distribution in Java
I have a set of integers each of which has a probability assigned, derived from earlier experiments, e.g.:
0 = 0.5
1 = 0.2
2 = 0.3
Complying with the specifications of a probability distribution, ...
8
votes
3
answers
301
views
Way to infer the size of the userbase of a site from sampling taken usernames
Suppose you wanted to estimate the size of a userbase of a site which does not publicize this information.
People are more likely to have acquired different usernames with different probabilities. ...
8
votes
1
answer
17k
views
Calculating Probability of a Random Variable in a Distribution in Python
Given a mean and standard-deviation defining a normal distribution, how would you calculate the following probabilities in pure-Python (i.e. no Numpy/Scipy or other packages not in the standard ...
8
votes
3
answers
640
views
re-using random number in reservoir sampling
It was asked in relation to another question recently: Given an unknown length list, return a random item in it by scanning it only 1 time
I know you shouldn't, I just can't put my finger on a ...
8
votes
5
answers
3k
views
Histogram matching - image processing - c/c++
I have two histograms.
int Hist1[10] = {1,4,3,5,2,5,4,6,3,2};
int Hist1[10] = {1,4,3,15,12,15,4,6,3,2};
Hist1's distribution is of type multi-modal;
Hist2's distribution is of type uni-modal with ...
8
votes
2
answers
4k
views
Algorithm for calculating probabilities of a number being drawn opening a book
I have a book with N<10000 pages, and a number x(in the range 1<=x<=40).
I want to calculate the probability that, opening that book at random, the combination of the digits of the opened ...
7
votes
3
answers
8k
views
Choosing n numbers with fixed sum
In some code I want to choose n random numbers in [0,1) which sum to 1.
I do so by choosing the numbers independently in [0,1) and normalizing them by dividing each one by the total sum:
numbers = [...
7
votes
2
answers
14k
views
Probability notation [closed]
I want to ask you about the notation in probability.
I know that
P(A | B) = the conditional probability that event A occurs given that
event B has occurred already
But I cannot find what A,B ...
7
votes
5
answers
2k
views
Efficiently summing log quantities
Working in C++, I'd like to find the sum of some quantities, and then take the log of the sum:
log(a_1 + a_2 + a_3 + ... + a_n)
However, I do not have the quantities themselves, I only have their ...
7
votes
3
answers
5k
views
Probability of 3-character string appearing in a randomly generated password
If you have a randomly generated password, consisting of only alphanumeric characters, of length 12, and the comparison is case insensitive (i.e. 'A' == 'a'), what is the probability that one specific ...
7
votes
1
answer
2k
views
What are the ways of deciding probabilities in hidden markov models?
I am starting to learn hidden markov models and on the wiki page, as well as on github there are alot of examples but most of the probabilities are already there(70% change of rain, 30% chance of ...
7
votes
3
answers
10k
views
Implement probability distribution function in Java problem
I have a function which is in the form of probability distribution function as below:
Although I discover some lib providing function to obtain the result as the above formula would do; but I am ...
6
votes
4
answers
7k
views
Implementing probability distribution function in Java
I'm trying to implement a probability distribution function in java where it returns the ith entry in the array with probability:
Fi = 6i(n-i) / (n3 - n)
where n is the array length i.e. for an ...
6
votes
2
answers
2k
views
generate a random point within rectangles' areas uniformly (some rectangles could overlap)
Assume it's given a set of rectangles with different areas and some rectangles could overlap.
Objective is generating of a uniform random point among rectangles' areas.
Rectangle is defined as a pair ...
6
votes
2
answers
2k
views
Algorithm to get probability of reaching a goal
Okay, I'm gonna be as detailed as possible here.
Imagine the user goes through a set of 'options' he can choose. Every time he chooses, he get, say, 4 different options. There are many more options ...
5
votes
4
answers
7k
views
Standard C or Python libraries to compute standard deviation of normal distribution
Say we have normal distribution n(x): mean=0 and \int_{-a}^{a} n(x) = P.
What is the easiest way to compute standard deviation of such distribution? May be there are standard libraries for python or ...
5
votes
7
answers
611
views
How many times can you randomly generate a GUID before you risk duplicates? (.NET)
Mathematically I suppose it's possible that even two random GUIDs generated using the built in method in the .NET framework are identical, but roughly how likely are they to clash if you generate ...
5
votes
2
answers
868
views
What is the expected number of subarrays of size 0, 1 and 2 when quicksort is used to sort an array of N items with distinct keys?
I am reading Robert Sedgewick's book Algorithms 4th edition, and he has the following exercise question: What is the expected number of subarrays of size 0, 1 and 2 when quicksort is used to sort an ...
5
votes
5
answers
4k
views
Random numbers with arbitrary probability distribution using rand() only
I am looking for a simple algorithm how to generate pseudo-random floating point numbers using only ANSI rand() function but with arbitrary probability distribution. For a simple uniform distribution ...
5
votes
2
answers
2k
views
Algorithm for probability when looping over a randomly ordered array
The problem is pretty straightforward, I think, by looking at the code. I have a randomized array (the array must be randomized, some code has been excluded because it doesn't pertain to the actual ...
5
votes
1
answer
7k
views
Calculate F-distribution p values in python?
Suppose that I have an F value and the associated degrees of freedom, df1 and df2. How can I use python to programmatically calculate the p value associated with these numbers?
Note: I would not ...