java.util.Random 挖得有点深

java.util.Random digging a bit deep

我在阅读 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;因为很可能会生成 0。然而,这只是一个猜测。我找不到公式。 java documentation 没有指定随机方程,我在这里或使用 Google.

搜索后都找不到任何相关主题

我想得到一些关于概率公式的帮助。提前致谢。

https://docs.oracle.com/javase/7/docs/api/java/util/Random.html#nextInt(int)

如您所料,它将是 0

r.nextInt(10)

将 return 个数字从 0 到 9

任何 0 * 1-9 的乘积都将为 0,因此对于 100 个随机数,此函数 return 没有 0 的可能性非常低。

数组元素的可能值为 0 .. 9,每个元素的概率为 1/10。如果其中一个元素为 0,则乘积也将为 0。所以我们计算至少有一个元素为0的概率。

事实证明,这与所有元素都大于零相反。一个元素大于0的概率是9/10,所有元素都大于0的概率因此是(9/10)^100.

因此,至少有一个元素为 0 的概率为 1 - (9/10)^100,大约为 0.9999734。

关于 nextInt:javadoc 指定:

uniformly distributed int value between 0 (inclusive) and the specified value (exclusive)

a "uniform distribution" 是一种分布,其中每个结果的可能性均等。

因此,特定结果的概率为“1/[可能结果的数量]”(因此它们加起来为 1)。

关于数组: 填充数组可以看作是观察100个统计上独立的事件。

您应该仔细阅读合并多个独立事件时的数学原理。