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.

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.

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

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}$.

share|improve this answer
3  
Just a side note, as I'm sure you are aware, there are many other ways besides using the inverse cdf to take uniform random variates and obtain normally distributed ones. Perhaps one of the very simplest algorithmically is the Box-Muller transform. Both Wichura's AS 241 and Acklam's algorithms provide high precision approximations to the inverse cdf using reasonably low-degree rational functions. –  cardinal Sep 26 '11 at 7:50
1  
@cardinal, you are absolutely right. But the link is Box-Muller transform. –  Did Sep 26 '11 at 8:00
    
@Didier: Thanks so much for your keen eye! I've reported this on meta as it appears to be a site bug. –  cardinal Sep 26 '11 at 8:25
    
I got this to work—thanks! Is there any reason to use log e instead of ln? Isn't it the same thing? (pardon my lack of experience in higher math) –  Tom Marthenal Sep 26 '11 at 18:24
    
@Tom: There is no difference between $\log_e$ and $\ln$ except personal preference and style. –  Henry Sep 26 '11 at 23:59
add comment

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

share|improve this answer
add comment

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} $$

share|improve this answer
add comment

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.