我正在阅读 Java 书中的数据结构和算法,我遇到了以下问题,我想获得帮助:
Suppose you are given an array, A, containing 100 integers that were generated using the method r.nextInt(10), where r is an object of type java.util.Random. Let x denote the product of the integers in A. There is a single number that x will equal with probability at least 0.99. What is that number and what is a formula describing the probability that x is equal to that number?
我认为x
等于零;因为很可能会生成 0。然而,这只是一个猜测。我找不到公式。 java documentation没有指定随机化方程,我在这里或使用 Google 搜索后都找不到任何相关主题。
我想得到一些关于概率公式的帮助。提前致谢。
最佳答案
数组元素的可能值为 0 .. 9,每个元素的概率为 1/10。如果其中一个元素为 0,则乘积也将为 0。所以我们计算至少一个元素为0的概率。
事实证明,这与所有元素都大于零相反。一个元素大于0的概率是9/10,因此所有元素都大于0的概率是(9/10)^100。
因此,至少有一个元素为 0 的概率为 1 - (9/10)^100,大约为 0.9999734。
关于java.util.Random 深入挖掘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34926464/