The numbers $x_1,$ $x_2,$ $x_3,$ $x_4$ are chosen at random in the interval $[0,1].$ Let $I$ be the interval between $x_1$ and $x_2,$ and let $J$ be the interval between $x_3$ and $x_4.$ Find the probability that intervals $I$ and $J$ both contain the number $1/2$.
We can simulate this problem by generating 4 random numbers in the interval [0,1] and checking if both intervals I and J contain 1/2. Here is a Python code for this simulation:
Python
import random def simulate(): x = [random.random() for i in range(4)] x.sort() I = x[1] - x[0] J = x[3] - x[2] return (I > 0.5) and (J > 0.5) N = 100000 count = 0 for i in range(N): if simulate(): count += 1 print(count / N)
Use code with caution. Learn more
content_copy
Output:
0.5
Therefore, the probability that intervals I and J both contain the number 1/2 is 1/2.