probability

Percentage Based Probability

我是研究僧i 提交于 2019-11-29 06:44:37
I have this code snippet: Random rand = new Random(); int chance = rand.Next(1, 101); if (chance <= 25) // probability of 25% { Console.WriteLine("You win"); } else { Console.WriteLine("You lose"); } My question is, does it really calculate a 25% probability for winning here? Is the chance of winning for the player here is really 25%? Edit: I just wrote this: double total = 0; double prob = 0; Random rnd = new Random(); for (int i = 0; i < 100; i++) { double chance = rnd.Next(1, 101); if (chance <= 25) prob++; total++; } Console.WriteLine(prob / total); Console.ReadKey(); And it's highly

Is Pythons random.randint statistically random?

蹲街弑〆低调 提交于 2019-11-29 04:50:32
So I'm testing an calculating the probabilities of certain dice rolls, for a game. The base case if that rolling one 10sided die. I did a million samples of this, and ended up with the following proportions: Result 0 0.000000000000000% 1 10.038789961210000% 2 10.043589956410000% 3 9.994890005110000% 4 10.025289974710000% 5 9.948090051909950% 6 9.965590034409970% 7 9.990190009809990% 8 9.985490014509990% 9 9.980390019609980% 10 10.027589972410000% These should of course all be 10%. There is a standard deviation of 0.0323207% in these results. that, to me, seems rather high. Is it just

Algorithm to find hole in an infinite one dimensional graph

岁酱吖の 提交于 2019-11-29 04:47:28
A cow is standing in front of an infinite fence . On the other side is grass. The cow wants to get to this grass. Somewhere along this fence is a hole through which the cow can get to the other side. The distance d from the cow to the hole has a probability distribution f(d) associated with it i.e. the probability that the hole is k steps away from the cow is given by f(k). Note that we think of all distances as discrete i.e. they are always measured in terms of steps taken by the cow.The cow can take negative integer steps as well as positive integer steps, i.e. k steps to the left and steps

What is the probability of guessing (matching) a Guid?

♀尐吖头ヾ 提交于 2019-11-29 03:48:34
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 jason It's not clear what you're asking. I see two ways to interpret your question. Given a GUID g , what is the probability of someone guessing it? Let's assume for simplicity that all 128 bits of a GUID are available. Then the probability of guessing g is 2^-128 . That's small. Let's get some intuition around that. Let's assume that our attacker can generate one billion GUIDs per second. To have a 50% chance of

Choose random array element satisfying certain property

[亡魂溺海] 提交于 2019-11-29 03:45:22
Suppose I have a list, called elements , each of which does or does not satisfy some boolean property p . I want to choose one of the elements that satisfies p by random with uniform distribution. I do not know ahead of time how many items satisfy this property p . Will the following code do this?: pickRandElement(elements, p) randElement = null count = 0 foreach element in elements if (p(element)) count = count + 1 if (randInt(count) == 0) randElement = element return randElement ( randInt(n) returns a random int k with 0 <= k < n .) It works mathematically. Can be proven by induction.

Estimate Markov Chain Transition Matrix in MATLAB With Different State Sequence Lengths

感情迁移 提交于 2019-11-29 02:41:25
I'm trying to build the transition matrix for a Markov Chain in MATLAB; I have several different observation sequences (all of varying lengths) and I need to generate the transition matrix using those. Constructing a multi-order Markov chain transition matrix in Matlab shows me how to build a transition matrix with a single observation sequence. How can I construct one using observations of different length? One example can be that one sequence is 1,2,3,4 and another is 4,5,6. Is there any way to do this without having to for loop through all sequences and computing counts? So for Markov

How to generate a random number from specified discrete distribution?

…衆ロ難τιáo~ 提交于 2019-11-29 02:08:06
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 results? How to make it in O(logn): - Make an array with cumulative probability (Array[i] = Probability that random number will be less or equal to i) - Generate random number from uniform distribution (lets denote it by k) - Find the smallest i such that k < Array[i]. It can be done using binary search. - i is our random number. Tom Minka Walker's alias method can draw a sample in constant worst

Plot probability heatmap/hexbin with different sized bins

∥☆過路亽.° 提交于 2019-11-29 01:30:55
This is related to another question: Plot weighted frequency matrix . I have this graphic (produced by the code below in R): #Set the number of bets and number of trials and % lines numbet <- 36 numtri <- 1000 #Fill a matrix where the rows are the cumulative bets and the columns are the trials xcum <- matrix(NA, nrow=numbet, ncol=numtri) for (i in 1:numtri) { x <- sample(c(0,1), numbet, prob=c(5/6,1/6), replace = TRUE) xcum[,i] <- cumsum(x)/(1:numbet) } #Plot the trials as transparent lines so you can see the build up matplot(xcum, type="l", xlab="Number of Trials", ylab="Relative Frequency",

Which java-library computes the cumulative standard normal distribution function?

[亡魂溺海] 提交于 2019-11-28 23:52:21
For a project I have a specification with formulas, I have to implement. In these formulas a cumulative standard normal distribution function exists, that takes a float and outputs a probability. The function is symbolized by a Φ. Exists a Java-library, that computes this function? Yuval Adam Apache Commons - Math has what you are looking for. More specifically, check out the NormalDistribution class. If you want the exact code, this one seems to be the same function used in OpenOffice Calc (I've made some changes for it to work in java): // returns the cumulative normal distribution function

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

ε祈祈猫儿з 提交于 2019-11-28 23:29:55
问题 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 to identify the documents by using the first x characters of the full digest. What's a good value for x if the number of documents is maybe around 10K - 100K? 回答1: Adapting the formulas on on wikipedia for the Birthday problem, you can approximate the probability of collision as e^(-n^2/(2^(b+1))