4
$\begingroup$

I am trying to develop a function that will allow me to input a random number between 0 and 1 and receive a value. The idea is that the function has a range (for example, 0-100) with a median value of 50.

I want something similar to a normal distribution of values:

The idea is that if I put in an arbitrary number of random inputs between 0 and 1, the vast majority of outputs will be near 50. Outputs near 0 or 100 would be very rare.

I have been attempting to read the Wikipedia article on probability distribution, but the knowledge needed to write a function eludes me.

So: what kind of function do I need to use in order for the results of that function to be in a normal distribution with domain [0, 1].

Thanks for the help. Explanations or suggestions on where to find explanations for anything above an Algebra II level would be greatly appreciated.

3 Answers 3

3

If you want a normal distribution, than you need the inverse of the cumulative distribution function of the normal distribution, as DeepYellow. This is not easy to develop from scratch.

If you just want want a bell-shaped curve, then the inverse of the CDF of the logistic distribution may meet your needs. If $X$ is your uniform random variable then you can use $F^{-1}(X)=\mu + s\,\log_e\left(\frac{X}{1-X}\right)$ which has mean and median $\mu$ (50 in your case). You can adjust $s$ to meet your needs: the logistic distribution has standard deviation $\pi s / \sqrt{3}$.

  • 0
    @Tom: There is no difference between $\log_e$ and $\ln$ except personal preference and style.2011-09-26
0

If you use the inverse of your CDF (Cumulative distribution function), then random values on the interval (0, 1) will have the PDF distribution. For the standard normal distribution, the inverse CDF is:

$ \sqrt{2}\; \text{InverseErf}(-1+2 \tau ) $

(according to Mathematica)

For various sample sizes (along the vertical axis), here's the distribution I got: enter image description here

0

You could use the Box–Muller transform. It takes two independent random variables $U_1,U_2$ uniformly distributed on $[0,1]$ as input and it returns two independent random variables $Z_1,Z_2$ that are normally distributed with expectation $0$ and variance $1$. Then let $X_i=50+\sigma Z_i$ for $i=1,2$, where $\sigma$ is whatever you want the standard deviation to be. If $\sigma$ is small, these would have only a tiny probability of failing to be between $0$ and $100$.

Here's how it's done: $ \begin{align} Z_1 & = \sqrt{-2\log_e U_1}\sin(2\pi U_2), \\ \\ Z_2 & = \sqrt{-2\log_e U_1}\cos(2\pi U_2). \end{align} $