# Generating random variables from standard uniform distribution on $(1,0)$

A random number generator generates random values from the standard uniform distribution $\mathrm{Uniform}(0,1)$. Call this random variable $U$. Starting with a random value $u$ from $U$, show all the steps necessary to generate a random variable $X$ such that the probability mass function $p(x)$ of $X$ is:

$p(1)=0.3$

$p(2)=0.15$

$p(3)=0.35$

$p(4)=0.2$

I'm not looking for an exact answer as much as an explanation to help with these problems in the future.

-

1
Try partioning $[0,1]$ into disjoint parts with lengths given by your probabilities using the fact that $P(a\leq U\leq b)=b-a$ when $a<b$ and $a,b\in[0,1]$. – Stefan Hansen Nov 20 '12 at 19:46

## 1 Answer

Your random number generator will produce (pseudo) random numbers uniformly distributed on $(0,1)$.

Suppose that we want to simulate a random variable $X$ which takes on value $3$ with probability $0.25$, value $7$ with probability $0.35$, and value $45.6$ with probability $0.40$ (of course, this is not your problem, just a similar one).

Use the following idea. If the random number generator produces a number between $0$ and $0.25$, report that $X$ has taken on value $3$.

If the random number generator produces a number between $0.25$ and $0.25+0.35$, that is, between $0.25$ and $0.60$, report that $X$ has taken on the value $7$.

Finally, if the random number generator produces a number between $0.25+0.35$ and $1$, report that $X$ has taken on the value $45.6$.

Note that the probability that the random number generator produces a number between $0$ and $0.25$ is $0.25$. So with probability $0.25$ we will be reporting that $X$ has taken on value $3$. The probability that the random number generator produces a number between $0.25$ and $0.25+0.35$ is $0.35$, so with probability $0.35$ we will be reporting that $X$ has taken on value $17$. And so on.

Remarks: 1) In principle, the random number generator produces "random" reals between $0$ and $1$. So the probability it produces a particular number $u$, like $1/\pi$, is $0$. In practice, the numbers produced are say decimals, to $10$ decimal places. So our program needs to deal with the highly improbable but possible situations where the random number produced is exactly at a boundary, like $0.25$. It doesn't really matter what we do.

2) The procedure we use can also be described in terms of the cumulative distribution function of the random variable we are trying to simulate. Perhaps you are expected to do it in that style, in preparation for more complex problems when we are simulating a continuously distributed random variable $X$. If a description in terms of the cdf is required, please indicate.

-
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 58, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9159103035926819, "perplexity_flag": "head"}