# Random number distribution from a different distribution

Suppose I have a random number generator that generates random numbers $x$ with a normal distribution

$p(x) \propto e^{-x^2}$

(modulo normalization, but lets keep it simple).

Now, out of these random numbers I'd like to generate random numbers $y$ with a slightly modified distribution:

$p(y) \propto e^{-a^2y^2}$.

I can achieve this by setting

$e^{-a^2y^2}=e^{-(ay)^2} \overset{!}{=} e^{-x^2}. \qquad (1)$

From what follows that $x=ay$ or $y=a^{-1}x$. Thus by multiplying my original numbers with $a^{-1}$ I get the desired distribution.

I am missing the logical argument for the second equal sign in equation (1). Why should I set desired probability $e^{-a^2y^2}$ equal to the probability of the random generator at hand?

Long form of angryavian's argument:

Let $Y=\frac1aX=g(X)$, with $X$ having pdf $f_X$, and $a>0$.

There is a standard way to find the pdf of Y: for any integrable function $h$,

$$E(h(Y))=\int_{-\infty}^\infty h(y) f_Y(y) \mathrm{d}y$$

But you have also

$$E(h(Y))=E(h(g(X)))=\int_{-\infty}^\infty h(g(x)) f_X(x) \mathrm{d}x=\int_{-\infty}^\infty h(x/a) f_X(x) \mathrm{d}x$$

Now do a change of variable $u=x/a$:

$$E(h(Y))=\int_{-\infty}^\infty h(y) f_Y(y) \mathrm{d}y=a\int_{-\infty}^\infty h(u) f_X(au) \mathrm{d}u$$

Since it's true for any $h$, you have $f_Y(y)=af_X(ay)$.

• This is nice and answers my question! Thank you! – ritter Aug 22 '14 at 18:58

If you want your modified random number $Y$ to follow the distribution $\propto e^{-a^2 y^2}$, the calculation there shows that $aY$ follows the distribution $\propto e^{-x^2}$, so what you can do is generate a random number $X$ from $\propto e^{-x^2}$, and then $X/a$ will follow the distribution $\propto e^{-a^2 y^2}$.

• "the calculation there" refers to eq. (1), right? Then I am not convinced. I am seeking for a motivation of eq. (1) – ritter Aug 22 '14 at 14:57