All Questions

Tagged with
Filter by
Sorted by
Tagged with
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 ...
aioobe's user avatar
  • 417k
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 ...
Tom Savage's user avatar
  • 3,182
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 ...
nimcap's user avatar
  • 10.2k
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 ...
Green goblin's user avatar
  • 9,936
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.
user339108's user avatar
  • 12.8k
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 ...
c00000fd's user avatar
  • 21.7k
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 ...
garima's user avatar
  • 5,194
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 ...
user avatar
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 ...
Eamonn McEvoy's user avatar
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 ...
Dark Nebula's user avatar
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 ...
user avatar
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 ...
ʞɔıu's user avatar
  • 47.8k
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
RhinoDevX64's user avatar
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 ...
Yuval Adam's user avatar
  • 163k
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 ...
sanity's user avatar
  • 35.5k
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 ...
Sami's user avatar
  • 3,263
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 ...
dmeister's user avatar
  • 35.1k
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/...
isapir's user avatar
  • 22.3k
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?
zino's user avatar
  • 1,362
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 ...
Phil H's user avatar
  • 20k
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 ...
Beska's user avatar
  • 12.6k
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 ...
jonalm's user avatar
  • 935
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 ...
Thad's user avatar
  • 1,520
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 ...
Ben S's user avatar
  • 68.8k
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, ...
Ricardo Sanchez-Saez's user avatar
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 ...
CoderMD666's user avatar
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'...
Dan Dinu's user avatar
  • 33k
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 ...
Holy semicolon's user avatar
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, ...
Carsten's user avatar
  • 1,952
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. ...
ʞɔıu's user avatar
  • 47.8k
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 ...
Cerin's user avatar
  • 63k
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 ...
Will's user avatar
  • 74.8k
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 ...
Raj's user avatar
  • 1,113
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 ...
Makers_F's user avatar
  • 3,053
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 = [...
Thomas Ahle's user avatar
  • 31.2k
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 ...
user1328370's user avatar
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 ...
Mike B's user avatar
  • 175
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 ...
Richard Pianka's user avatar
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 ...
Lostsoul's user avatar
  • 25.5k
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 ...
Alex Jones's user avatar
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 ...
user528676's user avatar
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 ...
Zhandos's user avatar
  • 279
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 ...
vedran's user avatar
  • 761
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 ...
elephantum's user avatar
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 ...
NibblyPig's user avatar
  • 52k
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 ...
Pavel's user avatar
  • 1
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 ...
psihodelia's user avatar
  • 29.9k
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 ...
A.B. Carroll's user avatar
  • 2,444
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 ...
Everyone_Else's user avatar

1
2 3 4 5
8