Probability of generating monotonically non-decreasing $\mathsf{Unif}(0,1)$ random numbers

119 Views Asked by At

I stumbled upon this post and I'm thinking if the problem can be generalized to continuous case.

In short, we generate $n$ random numbers, $X_1, X_2, ..., X_n$, which are uniformly distributed over the interval $[0, 1]$. The random numbers are i.i.d. What is $P(X_1 \le X_2 \le ... \le X_n)$?

2

There are 2 best solutions below

0
On

From the comments, it is clear that this problem is easily solved by combinatorial methods, so no simulation is needed to get the solution. You do not discuss your reason for wanting a simulation. But it is easy to show a relevant simulation in R statistical software, as below:

m = 10^6;  n = 5;  y = numeric(m)
for (i in 1:m) {
   x = runif(n);  s = sort(x)
   y[i] = sum(x==s) }
mean(y == n);  1/factorial(n);  round(factorial(n)*table(y)/m)
## 0.008197     # sim 1/5!
## 0.008333333  # exact 1/5!
## y
##  0  1  2  3  5 
## 44 45 20 10  1 

Table entries divided by $5!$ are probabilities of various counts of 'fixed points'. For example, 1/5! is the probability that all five $X_i$ are in sort order, and $44/5!$ is the probability that none of the $X_i$ are in sort order. That is $X_1 \ne X_{(i)},$ for all $i$. Perhaps you can find combinatorial solutions for those values.

There are more elegant ways to write such a program in R, using special features of the R language, but this method with an explicit 'for-loop' should be accessible to people who do not use R.

3
On

A simulation can also be implemented trivially in Mathematica:

F[n_, m_] := 10^m/Length[Select[RandomVariate[
  UniformDistribution[{0, 1}], {10^m, n}], OrderedQ]]

This generates $10^m$ samples of $n$ random $\operatorname{Uniform}(0,1)$ variables and counts the number of samples that were generated in nondecreasing sequence. Then it calculates the reciprocal of the incidence, so F[n,m] should return an number close to $n!$, with the accuracy increasing as the exponent $m$ increases.

Programming note: OrderedQ is quite a bit faster than # == Sort[#] & especially when $n$ is large, since the latter explicitly sorts each sample and then compares it to the original order to see if it is in order, whereas the former can just check by comparing each successive element to the previous and failing upon the first detection of a member that is less than the previous.