I have the following question asked in an interview: how can we use one generated random variable from uniform $U(0, 1)$ to generate two random variables from the same distribution $U(0, 1)$. My initial thoughts were to do some decomposition, say $x = f(x_1, x_2)$ where $x$ is from $U(0, 1)$ but in generally I was like headless on this decomposition. I am not sure how can we do this.
Asked
Active
Viewed 1,078 times
1
-
Is the question asking you to generate two independent uniform random variables? – angryavian Sep 05 '22 at 23:04
-
1Sure it was the only requirements?, if $x \sim U(0,,1)$ then the variable $y=1-x \sim U(0,,1)$, but are $100%$ correlated, so maybe they were asking for uncorrelated variables, right? – Joako Sep 05 '22 at 23:05
-
An old numerical trick, maybe not the best, was to generate $U$ on $(0,1)$, then to set $V$ to the fractional part of $1024\times U$, or some other multiplier which shifts the most significant bits. – A rural reader Sep 05 '22 at 23:21
1 Answers
4
There is a neat link between the uniform distribution and an infinite sequence of independent fair coin flips.
Sketch of one solution to the question that uses the above neat fact:
- Generate $x \sim U(0,1)$.
- Write $x$ in binary: $(0.x_1 x_2 x_3 \cdots)_2$ and use the above link to recognize that $x_1, x_2, x_3, \ldots$ is a sequence of independent $\text{Bernoulli}(1/2)$ random variables.
- Use the bits of this binary representation to create two new numbers $x' := (0.x_1 x_3 x_5 \cdots)_2$ and $x'' = (0.x_2 x_4 x_6 \cdots)$. Note that $x'$ and $x''$ are independent.
- Use the link again to recognize that $x'$ and $x''$ are each distributed according to $U(0,1)$.
As mentioned in the comments, if the two generated random variables need not be independent, you can instead simply return $x \sim U(0,1)$ and $y := 1-x$. Or even $x \sim U(0,1)$ and $y:=x$.
angryavian
- 93,534
-
1Is it necessary to first convert the number to binary? Why not just take the digits from even decimal points for one number and odd for the other? – Josh Jul 25 '23 at 19:17