Generating Gaussian Random Numbers

http://www.taygeta.com/random/gaussian.html

        This note is about the topic of generating

Gaussia 

        pseudo-random numbers given a source of

uniform 

        pseudo-random numbers. This topic comes up more frequently than I would have expected, so I decided to write this up on

one  of the best ways to do this. At the end of this note there is a list of references

        in the literature that are relevant to this topic. You can see some

code example

        that implement the technique, and a

tep-by-step

        example for generating

Weibull 

      distributed random numbers.

There are many ways of solving this problem (see for example Rubinstein, 1981, for an extensive discussion of this topic) but we will only go into one important method here. If we have an equation that describes our desired distribution function, then it is possible to use some mathematical trickery based upon the fundamental transformation law of probabilitiesto obtain a transformation function for the distributions. This transformation takes random variables from one distribution as inputs and outputs random variables in a new distribution function. Probably the most important of these transformation functions is known as the Box-Muller (1958) transformation. It allows us to transform uniformly distributed random variables, to a new set of random variables with a Gaussian (or Normal) distribution.

The most basic form of the transformation looks like:

         y1 = sqrt( - 2 ln(x1) ) cos( 2 pi x2 )
y2 = sqrt( - 2 ln(x1) ) sin( 2 pi x2 )
      We start with

two

      independent random numbers, x1 and x2, which come from a uniform distribution (in the range from 0 to 1). Then apply the above transformations to get two new independent random numbers which have a Gaussian distribution with zero mean and a standard deviation of one.

This particular form of the transformation has two problems with it,

      1. It is slow because of many calls to the math library.
      2. It can have numerical stability problems when x1 is very close to zero.

      These are serious problems if you are doing

stochastic modelling

      and generating millions of numbers.

The polar form of the Box-Muller transformation is both faster and more robust numerically. The algorithmic description of it is:

         float x1, x2, w, y1, y2;

         do {
x1 = 2.0 * ranf() - 1.0;
x2 = 2.0 * ranf() - 1.0;
w = x1 * x1 + x2 * x2;
} while ( w >= 1.0 ); w = sqrt( (-2.0 * log( w ) ) / w );
y1 = x1 * w;
y2 = x2 * w;
      where

ranf()

      is the routine to obtain a random number uniformly distributed in [0,1]. The polar form is faster because it does the equivalent of the sine and cosine geometrically without a call to the trigonometric function library. But because of the possiblity of many calls to

ranf()

      , the uniform random number generator should be fast (I generally recommend

R250

      for most applications).

Probability transformations for Non Gaussian distributions

      Finding transformations like the Box-Muller is a tedious process, and in the case of empirical distributions it is not possible. When this happens, other (often approximate) methods must be resorted to. See the reference list below (in particular

Rubinstein, 1981

      ) for more information.

There are other very useful distributions for which these probability transforms have been worked out. Transformations for such distributions as the Erlang, exponential,hyperexponential, and the Weibull distribution can be found in the literature (see for example,MacDougall, 1987).


Useful References

  • Box, G.E.P, M.E. Muller 1958; A note on the generation of random normal deviates, Annals Math. Stat, V. 29, pp. 610-611
    1. Carter, E.F, 1994; The Generation and Application of Random Numbers, Forth Dimensions Vol XVI Nos 1 & 2, Forth Interest Group, Oakland California
    1. Knuth, D.E., 1981; The Art of Computer Programming, Volume 2 Seminumerical Algorithms, Addison-Wesley, Reading Mass., 688 pages, ISBN 0-201-03822-6
    1. MacDougall,M.H., 1987; Simulating Computer Systems, M.I.T. Press, Cambridge, Ma., 292 pages, ISBN 0-262-13229-X
    1. Press, W.H., B.P. Flannery, S.A. Teukolsky, W.T. Vetterling, 1986; Numerical Recipes, The Art of Scientific Computing, Cambridge University Press, Cambridge, 818 pages, ISBN 0-512-30811-9
  1. Rubinstein, R.Y., 1981; Simulation and the Monte Carlo method, John Wiley & Sons, ISBN 0-471-08917-6

See Also

      : A

Reference list

    of papers on Random Number Generation.

 Everett (Skip) Carter          Phone: 831-641-0645 FAX:  831-641-0647
Taygeta Scientific Inc. INTERNET: skip@taygeta.com
1340 Munras Ave., Suite 314 UUCP: ...!uunet!taygeta!skip
Monterey, CA. 93940 WWW: http://www.taygeta.com/

Taygeta's Home page

Generating Gaussian Random Numbers(转)的更多相关文章

  1. C++ Standard-Library Random Numbers

    Extracted from Section 17.4 Random Numbers, C++ Primer 5th. Ed. The random-number library generates ...

  2. Random Numbers Gym - 101466K dfs序+线段树

    Tamref love random numbers, but he hates recurrent relations, Tamref thinks that mainstream random g ...

  3. 2017 ACM-ICPC, Universidad Nacional de Colombia Programming Contest K - Random Numbers (dfs序 线段树+数论)

    Tamref love random numbers, but he hates recurrent relations, Tamref thinks that mainstream random g ...

  4. [Python] Generating random numbers using numpy lib

    import numpy as np def test_run(): data=np.random.random((3,4)) """ [[ 0.80150549 0.9 ...

  5. Random numbers

    Most computer programs do the same thing every time they execute, given the same inputs, so they are ...

  6. [Swift] 随机数 | Random numbers

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  7. [Functional Programming] Pull Many Random Numbers in a Single State ADT Transaction

    We have the ability to select a single random card from a pile of twelve cards, but we would like to ...

  8. Generating a Random Sample from discrete probability distribution

    If is a discrete random variable taking on values , then we can write . Implementation of this formu ...

  9. K. Random Numbers(Gym 101466K + 线段树 + dfs序 + 快速幂 + 唯一分解)

    题目链接:http://codeforces.com/gym/101466/problem/K 题目: 题意: 给你一棵有n个节点的树,根节点始终为0,有两种操作: 1.RAND:查询以u为根节点的子 ...

随机推荐

  1. C#关键字之Partial详解

    Partial是局部类型的标志.局部类型可以实现将一个类.结构或接口分成几个部分,分别放在在几个不同的.cs文件中(当然也可以放在同一个.cs文件中).在程序进行编译之后,将会合并成一个完整的类.因此 ...

  2. rsync--数据镜像备份_转

    转载:rsync的配置使用 Rsync全称为remoterynchronization,rsync具有可使本地和远程两台主机之间的数据快速复制同步镜像.远程备份的功能,这个功能类似于scp命令,但优于 ...

  3. Linux进程状态转换图

    Linux进程状态 Linux内核中的进程状态 ◆运行状态(TASK_RUNNING) 指正在被CPU运行或者就绪的状态.这样的进程被成为runnning进程.运行态的进程可以分为3种情况:内核运行态 ...

  4. 快使用阿里云的maven仓库

    自从开源中国的maven仓库挂了之后就一直在用国外的仓库,慢得想要砸电脑的心都有了.如果你和我一样受够了国外maven仓库的龟速下载?快试试阿里云提供的maven仓库,从此不在浪费生命…… 仓库地址: ...

  5. JAVA源文件中是否可以包括多个类,有什么限制

    JAVA源文件中是否可以包括多个类,有什么限制 解答:一个java源文件中可以包含多个类,每个源文件中至多有一个public类,如果有的话,那么源文件的名字必须与之相同.如果源文件中没有public类 ...

  6. mfc小工具开发之定时闹钟之---二十四小时时区和时间段

    1.凌晨0:00-6:00时显示凌晨,上午6:00-12:00显示上午,中午12:00-14:00显示中午,下午14:00-显示下午,晚上18:00-24:00显示晚上 2. 早上:6-8:上午8-1 ...

  7. Pyscripter 不能正确调用另一文件中模块的问题的解析(Internal Engine 和 Remote Engine)

    背景 Pyscripter是python下一个非常流行的开源IDE,笔者一直使用Pyscripter来来编写python脚本. 关于IDE的一些特性本文不在赘述,主要是分享一下今天遇到的一个问题. 问 ...

  8. 2018 CCPC 桂林游记

    TYPE: Onsite Contest NAME: 2018 - CCPC - Guilin PLAT: HUSTOJ TIME: 2018/10/28 09:00-14:00 CST LOCA: ...

  9. cinder服务端的keystone认证机制

    keystone在openstack中的地位 Keystone作为OpenStack中的身份管理与授权模块,主要实现系统用户的身份认证.基于角色的授权管理.其他OpenStack服务的地址发现和安全策 ...

  10. MathType可以在Word、PPT中插入矩阵吗

    工科学生或者老师在写论文时最头痛的就是编辑公式,因为word自带的公式编辑器往往满足不了专业的公式需求,MathType就很好的解决了这个问题.在进行公式编辑时,难免会遇到输入矩阵的情况,那么怎么输入 ...