Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

share|improve this question
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 1

up vote 2 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.