- Timestamp:
- Mar 29, 2009, 6:15:31 PM (17 years ago)
- Location:
- branches/cnb_branches/cnb_branch_20090301
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ppSim/src/ppSimRandomGaussian.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/cnb_branches/cnb_branch_20090301
-
branches/cnb_branches/cnb_branch_20090301/ppSim/src/ppSimRandomGaussian.c
r18011 r23594 29 29 30 30 /* integrate a gaussian from -5 sigma to +5 sigma */ 31 void p_ppSimRandomGaussianInit ( ) {32 31 void p_ppSimRandomGaussianInit (void) { 32 33 33 int i; 34 34 long A, B; 35 35 double val, x, dx, dx1, dx2, dx3, df; 36 36 double mean, sigma; 37 37 38 38 /* no need to generate this if it already exists */ 39 39 if (gaussint) return; … … 42 42 for (B = 0; A == time(NULL); B++); 43 43 srand48(B); 44 44 45 45 Ngaussint = 0x1000; 46 46 ppSimRandomGaussianAlloc (Ngaussint + 1); … … 53 53 mean = 0.0; 54 54 sigma = 1.0; 55 55 56 56 for (i = 0, x = -7.0; (i < Ngaussint) && (x < 7.0); x += dx) { 57 df = (3.0*p_ppSimGaussian(x , mean, sigma) + 57 df = (3.0*p_ppSimGaussian(x , mean, sigma) + 58 58 9.0*p_ppSimGaussian(x+dx1, mean, sigma) + 59 9.0*p_ppSimGaussian(x+dx2, mean, sigma) + 59 9.0*p_ppSimGaussian(x+dx2, mean, sigma) + 60 60 3.0*p_ppSimGaussian(x+dx3, mean, sigma)) * (dx1/8.0); 61 61 val += df; … … 67 67 } 68 68 69 // XXX we are using drand48() rather than the random var supplied by rnd 69 // XXX we are using drand48() rather than the random var supplied by rnd 70 70 double ppSimRandomGaussian (const psRandom *rnd, double mean, double sigma) { 71 71 72 72 int i; 73 73 double y; 74 74 75 75 if (gaussint == NULL) { 76 76 p_ppSimRandomGaussianInit (); … … 80 80 i = Ngaussint*y; 81 81 y = gaussint[i]*sigma + mean; 82 82 83 83 return (y); 84 84 85 85 } 86 87 // XXX we are using drand48() rather than the random var supplied by rnd 86 87 // XXX we are using drand48() rather than the random var supplied by rnd 88 88 double ppSimRandomGaussianNorm (const psRandom *rnd) { 89 89 90 90 int i; 91 91 double y; 92 92 93 93 if (gaussint == NULL) { 94 94 p_ppSimRandomGaussianInit (); … … 98 98 i = Ngaussint*y; 99 99 y = gaussint[i]; 100 100 101 101 return (y); 102 102 }
Note:
See TracChangeset
for help on using the changeset viewer.
