Project

General

Profile

Revision 1000

Added by Ben Poole about 15 years ago

working gaussian nosie function: gauss_noise()

View differences:

gauss.c
11 11

  
12 12
#include <stdlib.h>
13 13
#include <math.h>
14
#include <gauss.h>
14
#include "gauss.h"
15 15

  
16 16
float chaos_scalar;
17
float gauss_noise( )
17

  
18
float gauss_noise(void)
18 19
{
20
    float x1, x2, w, y1, y2;
19 21

  
20
	srand( SEED );
21
	
22
	do 
23
	{
24
		x1 = 2.0 * rand()/RAND_MAX - 1.0;
25
        x2 = 2.0 * rand()/RAND_MAX - 1.0;
26
        w = x1 * x1 + x2 * x2;
27
    }
28
	while ( w >= 1.0 );
29

  
30
    w = sqrt( (-2.0 * M_LOG2E( w ) ) / w );
31
    y1 = x1 * w;
32
    y2 = x2 * w;
33
	return y1;
22
    srand( SEED );
23
    do 
24
    {
25
	x1 = 2.0 * rand()/RAND_MAX - 1.0;
26
	x2 = 2.0 * rand()/RAND_MAX - 1.0;
27
	w = x1 * x1 + x2 * x2;
28
    } while ( w >= 1.0 );
29
    w = sqrt( (-2.0 * log( w ) ) / w );
30
    return (x1 * w);
34 31
}
35 32

  
36 33

  

Also available in: Unified diff