Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Normal distribution starting with a uniformed distribution

  1. Mar 21, 2015 #1
    Hi comunity! I need to make a code o a normal distribution of velocities, starting whit a random secuence uniformly distributed between [0,1]. I am using FNT95, with Plato. I want to obtain a ''for'' bucle with I=1,N for the velocities.
    It is importan for the distribution to have sigma defined.
    The code is:

    Code (Fortran):
    PARAMETER (N=125)
    INTEGER (SELECTED_INT_KIND(4)) I !Átomo I-ésimo
    REAL, DIMENSION(1:N):: VX(N), VY(N), VZ(N)

        DO 200 I=1,N
    Could anyone help me?? Thank you!!! :nb)
  2. jcsd
  3. Mar 21, 2015 #2


    User Avatar
    Gold Member

    The simplest way to generate a normally distributed variable from uniform ones is probably to use two independent variables U, V, both uniformly distributed on [0,1].

    If you want ## X\sim \mathcal{N}(\mu_X,\sigma_X) ## ,

    Set ## X=\mu_X+\sigma_X \sqrt{-2 \ln(2\pi U)}\cos(2\pi V) ##

    You actually obtain a pair of independent normal variables this way, the second one being :

    ## Y=\mu_Y+\sigma_Y \sqrt{-2 \ln(2\pi U)}\sin(2\pi V) ##

    The reason behind this comes from looking at the bivariate normal distribution in polar coordinates.
    Last edited: Mar 21, 2015
  4. Mar 21, 2015 #3
    thank you! I have seen this algorithm before, but with sigma=1. It is very useful to my proyect!! Thans again!!! :smile:
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook