Changeset 3364 in Sophya for trunk/SophyaLib/BaseTools
- Timestamp:
- Oct 29, 2007, 6:34:27 PM (18 years ago)
- Location:
- trunk/SophyaLib/BaseTools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/srandgen.c
r3102 r3364 254 254 double pp,ppi,x; 255 255 int n; 256 ppi = pp = exp(-mu); 257 x = drand01(); 258 n = 0; 259 while (x > ppi) { 260 n++; 261 pp = mu*pp/(double)n; 262 ppi += pp; 263 } 264 return n; 265 } 266 267 /*! \ingroup BaseTools 268 \brief Poisson random number generator with approximation for large mean. 269 270 Return an integer value (>=0) corresponding a Poisson distribution with mean \b mu. 271 If \b mu is greater or equal than \b mumax, 272 the large number gaussian approximation is applied. 273 \b mumax=10 is a good value. 274 */ 275 unsigned long PoissRandLimit(double mu,double mumax) 276 // p(n) = (mu^n / n!) exp(-mu) for n = 0, 1, 2, ... 277 { 278 double pp,ppi,x; 279 unsigned long n; 280 281 if(mu>=mumax) { 282 pp = sqrt(mu); 283 while( (x=pp*NorRand()) < -mu ); 284 return (unsigned long)(mu+x+0.5); 285 } 286 256 287 ppi = pp = exp(-mu); 257 288 x = drand01(); -
trunk/SophyaLib/BaseTools/srandgen.h
r3099 r3364 74 74 75 75 int PoissRand(double mu); 76 unsigned long PoissRandLimit(double mu,double mumax /* =10. */ ); 76 77 77 78 TIREALEA *init_tirage_alea(int nbin,double xmin,double xmax,double (*fonc) (double));
Note:
See TracChangeset
for help on using the changeset viewer.