**References :** Posted by Alexey Menshikov

**Notes :**

Code I use sometimes, but don't remember where I ripped it from.

- Alexey Menshikov

**Code :**

#define ranf() ((float) rand() / (float) RAND_MAX)

float ranfGauss (int m, float s)

{

static int pass = 0;

static float y2;

float x1, x2, w, y1;

if (pass)

{

y1 = y2;

} else {

do {

x1 = 2.0f * ranf () - 1.0f;

x2 = 2.0f * ranf () - 1.0f;

w = x1 * x1 + x2 * x2;

} while (w >= 1.0f);

w = (float)sqrt (-2.0 * log (w) / w);

y1 = x1 * w;

y2 = x2 * w;

}

pass = !pass;

return ( (y1 * s + (float) m));

}

**Comments**

__from__ : davidchristenATgmxDOTnet

__comment__ : White Noise does !not! consist of uniformly distributed values. Because in white noise, the power of the frequencies are uniformly distributed. The values must be normal (or gaussian) distributed. This is achieved by the Box-Muller Transformation. This function is the polar form of the Box-Muller Transformation. It is faster and numeriacally more stable than the basic form. The basic form is coded in the other (second) post.
Detailed information on this topic:
http://www.taygeta.com/random/gaussian.html
http://www.eece.unm.edu/faculty/bsanthan/EECE-541/white2.pdf
Cheers David

__from__ : nick[DOT]a[DOT]shaw[AT]btopenworld[DOT]com

__comment__ : I'm trying to implement this in C#, but y2 isn't initialized. Is this a typo?

__from__ : foo[AT]bar[DOT]de

__comment__ : @nick: Way to late, but y2 will always be initialized as in the first run "pass" is 0 (i.e. false). The C# compiler just can't prove it.

__from__ : asynth[AT]gmail[DOT]com

__comment__ : David is wrong. The distribution of the sample values is irrelevant. 'white' simply describes the spectrum. Any series of sequentially independent random values -- whatever their distribution -- will have a white spectrum.

__from__ : aleyuwo[AT]popp[DOT]eamale[DOT]com

__comment__ : [url=http://dutasterideavodartonline.org/]dutasterideavodartonline.org.ankor[/url] <a href="http://online-purchaselevitra.net/">online-purchaselevitra.net.ankor</a> http://20mg-cheapest-pricelevitra.net/

__from__ : oboqamego[AT]g[DOT]eamale[DOT]com

__comment__ : [url=http://dutasterideavodartonline.org/]dutasterideavodartonline.org.ankor[/url] <a href="http://online-purchaselevitra.net/">online-purchaselevitra.net.ankor</a> http://20mg-cheapest-pricelevitra.net/