Questions tagged [probability]

Consider if your question would be better at stats.stackexchange.com. Probability touches upon uncertainty, random phenomena, random numbers, random variables, probability distributions, sampling, combinatorics.

probability
Filter by
Sorted by
Tagged with
596 votes
15 answers
76k views

Cosmic Rays: what is the probability they will affect a program?

Once again I was in a design review, and encountered the claim that the probability of a particular scenario was "less than the risk of cosmic rays" affecting the program, and it occurred to me that I ...
Mark Harrison's user avatar
494 votes
16 answers
461k views

Find the similarity metric between two strings

How do I get the probability of a string being similar to another string in Python? I want to get a decimal value like 0.9 (meaning 90%) etc. Preferably with standard Python and library. e.g. ...
tenstar's user avatar
  • 10.2k
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
238 votes
1 answer
6k views

Minimizing NExpectation for a custom distribution in Mathematica

This relates to an earlier question from back in June: Calculating expectation for a custom distribution in Mathematica I have a custom mixed distribution defined using a second custom distribution ...
Jagra's user avatar
  • 3,149
197 votes
9 answers
85k views

Why is XOR the default way to combine hashes?

Say you have two hashes H(A) and H(B) and you want to combine them. I've read that a good way to combine two hashes is to XOR them, e.g. XOR( H(A), H(B) ). The best explanation I've found is touched ...
Nate Murray's user avatar
  • 3,921
148 votes
4 answers
15k views

Data structures for loaded dice?

Suppose that I have an n-sided loaded die, where each side k has some probability pk of coming up when I roll it. I’m curious if there is a good data structure for storing this information statically (...
templatetypedef's user avatar
140 votes
3 answers
10k views

Why does this random value have a 25/75 distribution instead of 50/50?

Edit: So basically what I'm trying to write is a 1 bit hash for double. I want to map a double to true or false with a 50/50 chance. For that I wrote code that picks some random numbers (just as an ...
gvlasov's user avatar
  • 19.3k
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
124 votes
10 answers
316k views

How to calculate probability in a normal distribution given mean & standard deviation?

How to calculate probability in normal distribution given mean, std in Python? I can always explicitly code my own function according to the definition like the OP in this question did: Calculating ...
clwen's user avatar
  • 20.4k
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
76 votes
13 answers
72k views

How to pick an item by its probability?

I have a list of items. Each of these items has its own probability. Can anyone suggest an algorithm to pick an item based on its probability?
Ruzanna's user avatar
  • 9,816
75 votes
3 answers
55k views

Probability of SHA1 collisions

Given a set of 100 different strings of equal length, how can you quantify the probability that a SHA1 digest collision for the strings is unlikely... ?
eastafri's user avatar
  • 2,206
75 votes
3 answers
58k views

How do Markov Chain Chatbots work?

I was thinking of creating a chatbot using something like markov chains, but I'm not entirely sure how to get it to work. From what I understand, you create a table from data with a given word and ...
Jordan's user avatar
  • 9,084
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
72 votes
10 answers
117k views

Multivariate normal density in Python?

Is there any python package that allows the efficient computation of the PDF (probability density function) of a multivariate normal distribution? It doesn't seem to be included in Numpy/Scipy, and ...
Benno's user avatar
  • 5,376
68 votes
11 answers
86k views

Random number with Probabilities

I am wondering what would be the best way (e.g. in Java) to generate random numbers within a particular range where each number has a certain probability to occur or not? e.g. Generate random ...
marc wellman's user avatar
  • 5,846
62 votes
11 answers
180k views

Normalizing a list of numbers in Python

I need to normalize a list of values to fit in a probability distribution, i.e. between 0.0 and 1.0. I understand how to normalize, but was curious if Python had a function to automate this. I'd ...
Adam_G's user avatar
  • 7,613
57 votes
2 answers
59k views

Probability of collision when using a 32-bit hash

I have a 10-character string key field in a database. I've used CRC32 to hash this field, but I'm worrying about duplicates. Could somebody show me the probability of collision in this situation? P.S.:...
nguyenngoc101's user avatar
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
45 votes
7 answers
74k views

Generate Random Boolean Probability

I only know how I can generate a random boolean value (true/false). The default probability is 50:50 But how can I generate a true false value with my own probability? Let's say it returns true with ...
Dark Side's user avatar
  • 705
44 votes
5 answers
88k views

Probability in Java

I was curious to know, how do I implement probability in Java? For example, if the chances of a variable showing is 1/25, then how would I implement that? Or any other probability? Please point me in ...
Jeel Shah's user avatar
  • 3,294
43 votes
2 answers
82k views

scikit-learn return value of LogisticRegression.predict_proba

What exactly does the LogisticRegression.predict_proba function return? In my example I get a result like this: array([ [4.65761066e-03, 9.95342389e-01], [9.75851270e-01, 2.41487300e-02], [...
Zelphir Kaltstahl's user avatar
41 votes
4 answers
174k views

R: Calculate and interpret odds ratio in logistic regression

I am having trouble interpreting the results of a logistic regression. My outcome variable is Decision and is binary (0 or 1, not take or take a product, respectively). My predictor variable is ...
Sudy Majd's user avatar
  • 415
38 votes
6 answers
50k 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, ...
Roughmar's user avatar
  • 305
38 votes
10 answers
5k views

An interview question: About Probability

An interview question: Given a function f(x) that 1/4 times returns 0, 3/4 times returns 1. Write a function g(x) using f(x) that 1/2 times returns 0, 1/2 times returns 1. My implementation is: ...
Sawyer's user avatar
  • 15.7k
36 votes
7 answers
53k views

How do I simulate flip of biased coin?

In unbiased coin flip H or T occurs 50% of times. But I want to simulate coin which gives H with probability 'p' and T with probability '(1-p)'. something like this: def flip(p): '''this ...
Pratik Deoghare's user avatar
36 votes
3 answers
52k views

How to get a classifier's confidence score for a prediction in sklearn?

I would like to get a confidence score of each of the predictions that it makes, showing on how sure the classifier is on its prediction that it is correct. I want something like this: How sure is ...
user3377126's user avatar
  • 2,131
33 votes
6 answers
29k views

How do I assess the hash collision probability?

I'm developing a back-end application for a search system. The search system copies files to a temporary directory and gives them random names. Then it passes the temporary files' names to my ...
sharptooth's user avatar
  • 169k
33 votes
7 answers
47k views

How do I programmatically calculate Poker Odds? [closed]

I'm trying to write a simple game/utility to calculate poker odds. I know there's plenty of resources that talk about the formulas to do so, but I guess I'm having trouble translating that to code. ...
Joel Martinez's user avatar
31 votes
5 answers
20k views

What are probabilistic data structures?

I have read about "probabilistic" data structures like bloom filters and skip lists. What are the common characteristics of probabilistic data structures and what are they used for?
free_easy's user avatar
  • 5,079
30 votes
7 answers
35k views

Generate random integers with probabilities

I'm a bit confused about how to generate integer values with probabilities. As an example, I have four integers with their probability values: 1|0.4, 2|0.3, 3|0.2, 4|0.1 How can I generate these ...
Headshota's user avatar
  • 21.3k
30 votes
2 answers
111k views

Plotting probability density function by sample with matplotlib [closed]

I want to plot an approximation of probability density function based on a sample that I have; The curve that mimics the histogram behaviour. I can have samples as big as I want.
Cupitor's user avatar
  • 11.3k
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
30 votes
8 answers
26k views

Distributed probability random number generator

I want to generate a number based on a distributed probability. For example, just say there are the following occurrences of each numbers: Number| Count 1 | 150 2 | ...
Mark Conway's user avatar
30 votes
9 answers
13k views

How to do weighted random sample of categories in python

Given a list of tuples where each tuple consists of a probability and an item I'd like to sample an item according to its probability. For example, give the list [ (.3, 'a'), (.4, 'b'), (.3, 'c')] I'd ...
John's user avatar
  • 303
30 votes
5 answers
31k views

Create Bayesian Network and learn parameters with Python3.x [closed]

I'm searching for the most appropriate tool for python3.x on Windows to create a Bayesian Network, learn its parameters from data and perform the inference. The network structure I want to define ...
Spu's user avatar
  • 483
30 votes
8 answers
14k views

Random boolean with weight or bias

I need to generate some random booleans. However I need to be able to specify the probability of returning true. As a results doing: private Random random = new Random(); random.nextBoolean(); will ...
diestl's user avatar
  • 2,040
28 votes
3 answers
76k views

Defining a white noise process in Python

I need to draw samples from a white noise process in order to implement a particular integral numerically. How do I generate this with Python (i.e., numpy, scipy, etc.)?
abcd's user avatar
  • 10.5k
28 votes
6 answers
13k views

How much can you truncate a SHA1 hash and be reasonably sure of having an unique ID?

I am making an application that stores documents and gives each one a UID based on a SHA1 digest of a few things including the timestamp. The digest has a lot of characters, and I want to allow users ...
dan's user avatar
  • 44.7k
27 votes
8 answers
8k views

Select random row from a PostgreSQL table with weighted row probabilities

Example input: SELECT * FROM test; id | percent ----+---------- 1 | 50 2 | 35 3 | 15 (3 rows) How would you write such query, that on average 50% of time i could get the row with id=...
Oleg Golovanov's user avatar
27 votes
1 answer
1k views

Why eigenvector & eigenvalue in LDA become zero?

I'd like to implement fast PLDA (Probabilistic Linear Discriminant Analysis) in OpenCV. in this, LINK fast PLDA have been implemented in Matlab and Python. One of the parts of PLDA is LDA. I've ...
Saeid's user avatar
  • 548
26 votes
4 answers
43k views

Confidence interval for binomial data in R?

I know that I need mean and s.d to find the interval, however, what if the question is: For a survey of 1,000 randomly chosen workers, 520 of them are female. Create a 95% confidence interval for the ...
Pig's user avatar
  • 2,072
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
8 answers
14k views

Game Design/theory, Loot Drop Chance/Spawn Rate

I have a very specific and long-winded question for you all. This question is both about programming and game-theory. I recently added spawnable ore to my Turn Based Strategy Game: http://imgur.com/...
Krythic's user avatar
  • 4,274
26 votes
9 answers
4k views

What's the best way to unit test code that generates random output?

Specifically, I've got a method picks n items from a list in such a way that a% of them meet one criterion, and b% meet a second, and so on. A simplified example would be to pick 5 items where 50% ...
Flynn1179's user avatar
  • 12k
26 votes
3 answers
22k views

How do I calculate the probability for a given quantile in R?

Using R, it is trivial to calculate the quantiles for given probabilities in a sampled distribution: x <- rnorm(1000, mean=4, sd=2) quantile(x, .9) # results in 6.705755 However, I can't find an ...
Andrew's user avatar
  • 37.4k
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
12 answers
6k views

Python - Is a dictionary slow to find frequency of each character?

I am trying to find a frequency of each symbol in any given text using an algorithm of O(n) complexity. My algorithm looks like: s = len(text) P = 1.0/s freqs = {} for char in text: try: ...
psihodelia's user avatar
  • 29.9k
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

1
2 3 4 5
82