Ignore:
Timestamp:
Apr 29, 2009, 12:14:04 PM (16 years ago)
Author:
ansari
Message:

Modifs,petites extensions + numero de version/initialisation de l'instance globale de RandomGenerator, Reza 29/04/2009

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/BaseTools/randinterf.cc

    r3602 r3604  
    1414//-------------------------------------------------------------------------------
    1515// ------ 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
     35RandomGeneratorInterface* 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*/
     43void 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}
    1650
    1751RandomGeneratorInterface::RandomGeneratorInterface()
    18   : usegaussian_(0), usepoisson_(0), useexpo_(0)
    19 {
     52{
     53  SelectGaussianAlgo();
     54  SelectPoissonAlgo();
     55  SelectExponentialAlgo();
    2056}
    2157 
     
    2662}
    2763
    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 }
    4264
    4365/////////////////////////////////////////////////////////////////////////
     
    150172}
    151173
    152 
    153 /////////////////////////////////////////////////////////////////////////
    154 /////////////////////////////////////////////////////////////////////////
    155 /////////////////////////////////////////////////////////////////////////
     174/////////////////////////////////////////////////////////////////////////
     175/////////////////////////////////////////////////////////////////////////
     176/////////////////////////////////////////////////////////////////////////
     177
     178r_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}
    156201
    157202//--- Generation de nombre aleatoires suivant une distribution gaussienne
     
    374419/////////////////////////////////////////////////////////////////////////
    375420
     421uint_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
    376437//--- Generation de nombre aleatoires suivant une distribution de Poisson
    377438uint_8 RandomGeneratorInterface::PoissonSimple(double mu,double mumax)
     
    634695/////////////////////////////////////////////////////////////////////////
    635696/////////////////////////////////////////////////////////////////////////
     697
     698r_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}
    636712
    637713r_8 RandomGeneratorInterface::ExpoSimple(void)
Note: See TracChangeset for help on using the changeset viewer.