Changeset 3604 in Sophya for trunk/SophyaLib/BaseTools/randinterf.cc
- Timestamp:
- Apr 29, 2009, 12:14:04 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/randinterf.cc
r3602 r3604 14 14 //------------------------------------------------------------------------------- 15 15 // ------ Definition d'interface des classes de generateurs de nombres aleatoires 16 /*! 17 \class RandomGeneratorInterface 18 \ingroup BaseTools 19 \brief Base class for random number generators 20 21 This class defines the interface for random number generator classes and 22 implements the generation of some specific distributions (Gaussian, Poisson ...) 23 through generation of random number with a flat distribution in the range [0,1[. 24 25 The sub classes inheriting from this class should implement the Next() method. 26 27 This base class manages also a global instance of a default generator. 28 29 \sa frand01 drand01 frandpm1 drandpm1 30 \sa GauRnd PoissRand 31 32 */ 33 34 35 RandomGeneratorInterface* RandomGeneratorInterface::gl_rndgen_p = NULL; 36 37 /*! 38 \brief: static method to set or change the intance of the global Random Generator object 39 40 This method should be called during initialization, before any call to global 41 functions for random number generation. The rgp object should be created using new. 42 */ 43 void RandomGeneratorInterface::SetGlobalRandGenP(RandomGeneratorInterface* rgp) 44 { 45 if (rgp == NULL) return; 46 if (gl_rndgen_p) delete gl_rndgen_p; 47 gl_rndgen_p = rgp; 48 return; 49 } 16 50 17 51 RandomGeneratorInterface::RandomGeneratorInterface() 18 : usegaussian_(0), usepoisson_(0), useexpo_(0) 19 { 52 { 53 SelectGaussianAlgo(); 54 SelectPoissonAlgo(); 55 SelectExponentialAlgo(); 20 56 } 21 57 … … 26 62 } 27 63 28 void RandomGeneratorInterface::UseGaussian(uint_2 type)29 {30 usegaussian_ = type;31 }32 33 void RandomGeneratorInterface::UseExpo(uint_2 type)34 {35 useexpo_ = type;36 }37 38 void RandomGeneratorInterface::UsePoisson(uint_2 type)39 {40 usepoisson_ = type;41 }42 64 43 65 ///////////////////////////////////////////////////////////////////////// … … 150 172 } 151 173 152 153 ///////////////////////////////////////////////////////////////////////// 154 ///////////////////////////////////////////////////////////////////////// 155 ///////////////////////////////////////////////////////////////////////// 174 ///////////////////////////////////////////////////////////////////////// 175 ///////////////////////////////////////////////////////////////////////// 176 ///////////////////////////////////////////////////////////////////////// 177 178 r_8 RandomGeneratorInterface::Gaussian() 179 { 180 switch (usegaussian_) { 181 case C_Gaussian_BoxMuller : 182 return GaussianBoxMuller(); 183 break; 184 case C_Gaussian_RandLibSNorm : 185 return GaussianSNorm(); 186 break; 187 case C_Gaussian_PolarBoxMuller : 188 return GaussianPolarBoxMuller(); 189 break; 190 case C_Gaussian_RatioUnif : 191 return GaussianRatioUnif(); 192 break; 193 case C_Gaussian_LevaRatioUnif : 194 return GaussianLevaRatioUnif(); 195 break; 196 default: 197 return GaussianBoxMuller(); 198 break; 199 } 200 } 156 201 157 202 //--- Generation de nombre aleatoires suivant une distribution gaussienne … … 374 419 ///////////////////////////////////////////////////////////////////////// 375 420 421 uint_8 RandomGeneratorInterface::Poisson(double mu, double mumax) 422 { 423 switch (usepoisson_) { 424 case C_Poisson_Simple : 425 return PoissonSimple(mu,mumax); 426 break; 427 case C_Poisson_Ahrens : 428 return PoissonAhrens(mu); 429 break; 430 default: 431 return PoissonSimple(mu,mumax); 432 break; 433 } 434 } 435 436 376 437 //--- Generation de nombre aleatoires suivant une distribution de Poisson 377 438 uint_8 RandomGeneratorInterface::PoissonSimple(double mu,double mumax) … … 634 695 ///////////////////////////////////////////////////////////////////////// 635 696 ///////////////////////////////////////////////////////////////////////// 697 698 r_8 RandomGeneratorInterface::Exponential() 699 { 700 switch (useexpo_) { 701 case C_Exponential_Simple : 702 return ExpoSimple(); 703 break; 704 case C_Exponential_Ahrens : 705 return ExpoAhrens(); 706 break; 707 default: 708 return ExpoSimple(); 709 break; 710 } 711 } 636 712 637 713 r_8 RandomGeneratorInterface::ExpoSimple(void)
Note:
See TracChangeset
for help on using the changeset viewer.