probability

Creating your own Tinyurl style uid

蓝咒 提交于 2019-11-27 11:15:49
I'm writing a small article on humanly readable alternatives to Guids/UIDs, for example those used on TinyURL for the url hashes (which are often printed in magazines, so need to be short). The simple uid I'm generating is - 6 characters: either a lowercase letter (a-z) or 0-9. "According to my calculations captain", that's 6 mutually exclusive events, although calculating the probability of a clash gets a little harder than P(A or B) = P(A) + P(B), as obviously it includes numbers and from the code below, you can see it works out whether to use a number or letter using 50/50. I'm interested

How to generate random numbers biased towards one value in a range?

陌路散爱 提交于 2019-11-27 10:53:58
问题 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 want to generate a random number between min and max but more biased towards a value N between min and max to a degree D ? It's best to illustrate it with a probability curve: 回答1: Here is one way: Get a random number in the min-max range Get a random normalized mix value Mix random with bias based on

Probability distribution in Python

笑着哭i 提交于 2019-11-27 10:45:30
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 unlikely (a more likely) object. I am wondering if you would have any suggestions, preferably an existing python module that I could use, else I will need to make it myself. I have checked out the random module; it does not seem to provide this. I have to make such choices many millions of times for 1000 different sets of objects each containing 2,455 objects. Each set will exchange objects among each

How to compute the probability of a value given a list of samples from a distribution in Python?

本秂侑毒 提交于 2019-11-27 10:11:14
问题 Not sure if this belongs in statistics, but I am trying to use Python to achieve this. I essentially just have a list of integers: data = [300,244,543,1011,300,125,300 ... ] And I would like to know the probability of a value occurring given this data. I graphed histograms of the data using matplotlib and obtained these: In the first graph, the numbers represent the amount of characters in a sequence. In the second graph, it's a measured amount of time in milliseconds. The minimum is greater

Random boolean with weight or bias

懵懂的女人 提交于 2019-11-27 09:24:38
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 not work. One possible solution would be: private Random random = new Random() public boolean getRandomBoolean(float p){ return random.nextFloat() < p; } I was wondering if there is a better or more natural way of doing this. EDIT: I guess I am asking whether there is a library class that provides a nextBoolean(float probability) method. Oliver Charlesworth I was wondering if there is a better or

Arc4random modulo biased

左心房为你撑大大i 提交于 2019-11-27 08:43:27
According to this documentation , arc4random_uniform() is recommended over constructions like arc4random() % upper_bound as it avoids "modulo bias" when the upper bound is not a power of two. How bad is the bias? For example if I generate random numbers with an upper bound of 6, what's the difference between using arc4random with % and arc4random_uniform() ? arc4random() returns an unsigned 32-bit integer, meaning the values are between 0 and 2^32-1 = 4 294 967 295. Now, the bias results from the fact that the multiple subintervals created with modulo are not fitting exactly into the random

Algorithm to generate Poisson and binomial random numbers?

强颜欢笑 提交于 2019-11-27 07:00:28
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 using this simple recipe: if x 1 , x 2 , ... is a sequence of random numbers with uniform distribution between zero and one, k is the first integer for which the product x 1 · x 2 · ... · x k+1 < e -λ i've found another page describing how to generate binomial numbers, but i think it is using an approximation of poisson generation, which doesn't help me. For example, consider binomial random numbers

Computing similarity between two lists

两盒软妹~` 提交于 2019-11-27 05:40:42
问题 EDIT: as everyone is getting confused, I want to simplify my question. I have two ordered lists. Now, I just want to compute how similar one list is to the other. Eg, 1,7,4,5,8,9 1,7,5,4,9,6 What is a good measure of similarity between these two lists so that order is important. For example, we should penalize similarity as 4,5 is swapped in the two lists? I have 2 systems. One state of the art system and one system that I implemented. Given a query, both systems return a ranked list of

Generate random integers with probabilities

断了今生、忘了曾经 提交于 2019-11-27 03:59:06
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 four numbers taking into account their probabilities? Here's a useful trick :-) function randomWithProbability() { var notRandomNumbers = [1, 1, 1, 1, 2, 2, 2, 3, 3, 4]; var idx = Math.floor(Math.random() * notRandomNumbers.length); return notRandomNumbers[idx]; } A simple naive approach can be: function getRandom(){ var num=Math.random(); if(num < 0.3) return 1; //probability 0.3 else if(num < 0.6)

how to implement non uniform probability distribution?

感情迁移 提交于 2019-11-27 03:49:02
问题 I am trying to implement non-uniform probability distribution in genetic algorithm. In the implementation of genetic program, I have an experiment which has 3 outcomes, where each outcome has different probabilities. Let say, probablity of one outcome is 0.85, other is 0.01 and last one is 0.14? P.S: i recently came to know that it is called non-uniform distribution of probability. I'm implementing it in Java, can anyone tell the theory behind non-uniform prob. distribution & also any Java