-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenRuidoRapido.c
70 lines (57 loc) · 1.73 KB
/
GenRuidoRapido.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Esta funcion genera el "Ruido Blanco Gaussiano" para cada particula
#ifndef GENRUIDORAPIDO_C
#define GENRUIDORAPIDO_C
#include <time.h>
#include <math.h>
// generador standard
#include <stdlib.h>
/*
// generador Alfredo
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int.hpp>
#include <boost/random/variate_generator.hpp>
boost::mt19937 rng; // produces randomness out of thin air
// see pseudo-random number generators
boost::uniform_int<> six(0,256*256*256); // distribution that maps to 1..6
// see random number distributions
boost::variate_generator<boost::mt19937&, boost::uniform_int<> >
irand(rng, six); // glues randomness with mapping
*/
void GenRuidoRapido(double *Noise, double Sigma, unsigned long int Tmax)
{
void Gasdev(double *V2, double Sig, long *idum);
unsigned long int i;
static long int sem = -1; // Semilla para el generador de numeros random.
if(sem==-1) sem =-time(NULL);
for(i=0; i<Tmax; i+=2) Gasdev(&(Noise[i]), Sigma, &sem);
}
/*
double getrand(void) {
return (double) irand() / (double) (256*256*256);
}
*/
void Gasdev(double *V2, double Sigma, long *idum)
{
double dran1(long *idum);
double fac,rsq,v1,v2;
do {
// generador stdlib.h [-1,1]
v1= 2.0* ((double) rand()/ (double) RAND_MAX )- 1.0;
v2= 2.0* ((double) rand()/ (double) RAND_MAX )- 1.0;
/*
// con semilla
v1=2.0*dran1(idum)-1.0;
v2=2.0*dran1(idum)-1.0;
*/
/*
// usando generador Alfredo
v1=2.0*getrand()-1.0;
v2=2.0*getrand()-1.0;
*/
rsq=v1*v1+v2*v2;
} while (rsq >= 1.0 || rsq == 0.0);
fac=Sigma*sqrt(-2.0*log(rsq)/rsq);
V2[0] = v2*fac;
V2[1] = v1*fac;
}
#endif