probability

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

好久不见. 提交于 2019-11-26 04:57:12
问题 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 didn\'t have the faintest idea what that probability is. \"Since 2 -128 is 1 out of 340282366920938463463374607431768211456, I think we\'re justified in taking our chances here, even if these computations are off by a factor of a few billion... We\'re way more at risk for cosmic rays to screw

Probability of SHA1 collisions

喜你入骨 提交于 2019-11-26 04:53:32
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... ? Peter Are the 160 bit hash values generated by SHA-1 large enough to ensure the fingerprint of every block is unique? Assuming random hash values with a uniform distribution, a collection of n different data blocks and a hash function that generates b bits, the probability p that there will be one or more collisions is bounded by the number of pairs of blocks multiplied by the probability that a given pair will collide. (source : http:/

Is it safe to assume a GUID will always be unique?

坚强是说给别人听的谎言 提交于 2019-11-26 04:38:53
问题 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 optimal way to test a GUID for uniqueness? Bloom filter maybe? 回答1: Yes, you can. Since GUIDs are 128 bits long, there is admittedly a minute possibility of a clash—but the word "minute" is nowhere near strong enough. There are so many GUIDs that if you generate several trillion of them randomly, you

How to pick an item by its probability?

人盡茶涼 提交于 2019-11-26 04:36:12
问题 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? 回答1: So with each item store a number that marks its relative probability, for example if you have 3 items one should be twice as likely to be selected as either of the other two then your list will have: [{A,1},{B,1},{C,2}] Then sum the numbers of the list (i.e. 4 in our case). Now generate a random number and choose that index. int index = rand

Data structure for loaded dice?

旧街凉风 提交于 2019-11-26 04:29:48
问题 Suppose that I have an n-sided loaded die where each side k has some probability p k of coming up when I roll it. I\'m curious if there is good algorithm for storing this information statically (i.e. for a fixed set of probabilities) so that I can efficiently simulate a random roll of the die. Currently, I have an O(lg n) solution for this problem. The idea is to store a table of the cumulative probability of the first k sides for all k, them to generate a random real number in the range [0,

Why is XOR the default way to combine hashes?

主宰稳场 提交于 2019-11-26 03:29:40
问题 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 briefly here on these hash function guidelines: XORing two numbers with roughly random distribution results in another number still with roughly random distribution*, but which now depends on the two values. ... * At each bit of the two numbers to combine, a 0 is output if the two bits are

Generate random number with given probability matlab

允我心安 提交于 2019-11-26 02:22:18
问题 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 of generating eg. 0.5 chance of 1 0.1 chance of 2 0.4 chance of 3 I\'m sure this is straightforward but I can\'t think of how to do it. 回答1: The simple solution is to generate a number with a uniform distribution (using rand), and manipulate it a bit: r = rand; prob = [0.5, 0.1, 0.4]; x = sum(r >=

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

笑着哭i 提交于 2019-11-26 02:09:35
问题 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: freqs[char]+=P except: freqs[char]=P but I doubt that this dictionary-method is fast enough, because it depends on the underlying implementation of the dictionary methods. Is this the fastest method? UPDATE: there is no increase in speed if collections and integers are used. It is because the algorithm is

Probability of SHA1 collisions

人盡茶涼 提交于 2019-11-26 01:54:21
问题 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... ? 回答1: Are the 160 bit hash values generated by SHA-1 large enough to ensure the fingerprint of every block is unique? Assuming random hash values with a uniform distribution, a collection of n different data blocks and a hash function that generates b bits, the probability p that there will be one or more collisions is bounded by the number of

Find the similarity metric between two strings

青春壹個敷衍的年華 提交于 2019-11-26 01:37:12
问题 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. similar(\"Apple\",\"Appel\") #would have a high prob. similar(\"Apple\",\"Mango\") #would have a lower prob. 回答1: There is a built in. from difflib import SequenceMatcher def similar(a, b): return SequenceMatcher(None, a, b).ratio() Using it: >>> similar("Apple","Appel") 0.8 >>> similar("Apple","Mango")