Gauss test.py

From Werner KRAUTH

Jump to: navigation, search

This page presents the program gauss_test.py, a direct-sampling algorithm for two independent Gaussian random numbers. This algorithm is used to illustrate the concept of "sample transformation"


Contents

Description

Program

import random, math

def gauss_test(sigma):
    phi = random.uniform(0.0, 2.0 * math.pi)
    Upsilon = random.uniform(0.0, 1.0)
    Psi = - math.log(Upsilon)
    r = sigma * math.sqrt(2.0 * Psi)
    x = r * math.cos(phi)
    y = r * math.sin(phi)
    return [x, y]

nsamples = 50
for sample in range(nsamples):
    [x, y] = gauss_test(1.0)
    print x, y

Version

See history for version information.

Personal tools