probability

what is the most efficient way to pick a random card from a deck when some cards are unusable?

限于喜欢 提交于 2019-11-27 02:27:48
问题 I have an array which tells whether a card is in use: int used[52]; This is a terrible way to pick a random card if I have many used cards: do { card = rand() % 52; } while (used[card]); since if I have only 3-4 unused cards, it'll take forever to find them. I came up with this: int card; int k = 0; int numUsed = 0; for (k=0; k < 52; ++k) { if (used[k]) numUsed += 1; } if (numUsed == 52) return -1; card = rand() % (52 - numUsed); for (k=0; k < 52; ++k) { if (used[k]) continue; if (card == 0)

Estimating/forecasting download completion time

时光毁灭记忆、已成空白 提交于 2019-11-27 02:17:51
问题 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 we need to use this to estimate the completion time, perhaps with an indication of certainty, like '20-25 mins remaining' using some Y% confidence interval. Code that did this could be put in a little library and used in projects all over, so is it really that difficult? How would you do it? What

JavaScript - How to randomly sample items without replacement?

倖福魔咒の 提交于 2019-11-27 02:06:52
JavaScript I've tried searching for something like this, but I am not able to find it. It's a simple idea: a. Take a random number between 0 to 10. b. Let's say the random number rolled is a 3. c. Then, save the number (the 3). d. Now, take another random number again between 0 to 10, but it can't be the 3, because it has already appeared. One solution is to generate an array (a "bucket") with all the values you want to pick, in this case all numbers from 0 to 10. Then you pick one randomly from the array and remove it from the bucket. Note that the example below doesn't check if the bucket is

Generate Random Numbers with Probabilistic Distribution

情到浓时终转凉″ 提交于 2019-11-27 00:58:26
问题 Ok, so here's my problem. We are looking at purchasing a data set from a company to augment our existing data set. For the purposes of this question, let's say that this data set ranks places with an organic number (meaning that the number assigned to one place has no bearing on the number assigned to another). The technical range is 0 to infinity, but from sample sets that I've seen, it's 0 to 70. Based on the sample, it's most definitely not a uniform distribution (out of 10,000 there are

How can I efficiently calculate the binomial cumulative distribution function?

廉价感情. 提交于 2019-11-27 00:38:15
问题 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 a failure). I want to know the approximate probability of seeing either S successes, or a number of successes less likely than S successes. So for example, if P is 0.3, N is 100, and I get 20 successes, I'm looking for the probability of getting 20 or fewer successes. If, on the other hadn, P is 0

Fitting distributions, goodness of fit, p-value. Is it possible to do this with Scipy (Python)?

狂风中的少年 提交于 2019-11-27 00:37:57
问题 INTRODUCTION: I'm a bioinformatician. In my analysis which I perform on all human genes (about 20 000) I search for a particular short sequence motif to check how many times this motif occurs in each gene. Genes are 'written' in a linear sequence in four letters (A,T,G,C). For example: CGTAGGGGGTTTAC... This is the four-letter alphabet of genetic code which is like the secret language of each cell, it’s how DNA actually stores information. I suspect that frequent repetations of a particular

How to calculate mean, median, mode and range from a set of numbers

流过昼夜 提交于 2019-11-27 00:06:11
问题 Are there any functions (as part of a math library) which will calculate mean, median, mode and range from a set of numbers. 回答1: Yes, there does seem to be 3rd libraries (none in Java Math). Two that have come up are: http://opsresearch.com/app/ http://www.iro.umontreal.ca/~simardr/ssj/indexe.html but, it is actually not that difficult to write your own methods to calculate mean, median, mode and range. MEAN public static double mean(double[] m) { double sum = 0; for (int i = 0; i < m.length

Probability of collision when using a 32 bit hash

感情迁移 提交于 2019-11-27 00:00:00
I have a 10 character string key field in a database. I've used CRC32 to hash this field but I'm worry about duplicates. Could somebody show me the probability of collision in this situation? p.s. my string field is unique in the database. If the number of string fields is 1 million, what is probability of collision ? Adam Morris Duplicate of Expected collisions for perfect 32bit crc The answer referenced this article: http://arstechnica.com/civis/viewtopic.php?f=20&t=149670 Found the image below from: http://preshing.com/20110504/hash-collision-probabilities In the case you cite, at least one

Select random row from a PostgreSQL table with weighted row probabilities

本秂侑毒 提交于 2019-11-26 23:27:56
问题 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=1, 35% of time row with id=2, and 15% of time row with id=3? I tried something like SELECT id FROM test ORDER BY p * random() DESC LIMIT 1 , but it gives wrong results. After 10,000 runs I get a distribution like: {1=6293, 2=3302, 3=405} , but I expected the distribution to be nearly: {1=5000, 2=3500, 3=1500} .

Probability Random Number Generator

末鹿安然 提交于 2019-11-26 20:40:55
问题 Let's say I'm writing a simple luck game - each player presses Enter and the game assigns him a random number between 1-6. Just like a cube. At the end of the game, the player with the highest number wins. Now, let's say I'm a cheater. I want to write the game so player #1 (which will be me) has a probability of 90% to get six, and 2% to get each of the rest numbers (1, 2, 3, 4, 5). How can I generate a number random, and set the probability for each number? 回答1: static Random random = new