# Gauss test.py

(Difference between revisions)
 Revision as of 21:18, 22 September 2015Werner (Talk | contribs)← Previous diff Current revisionWerner (Talk | contribs) Line 1: Line 1: + 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" + + __FORCETOC__ + =Description= + + =Program= import random, math import random, math Line 14: Line 20: [x, y] = gauss_test(1.0) [x, y] = gauss_test(1.0) print x, y print x, y + =Version= + See history for version information. + + [[Category:Python]] [[Category:Honnef_2015]] [[Category:MOOC_SMAC]]

## Current revision

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"

# 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.