Changeset 3613 in Sophya for trunk/SophyaLib/TArray/utilarr.cc


Ignore:
Timestamp:
Apr 30, 2009, 7:07:46 PM (16 years ago)
Author:
ansari
Message:

Adaptation a l'introduction de la suite des classes RandomGeneratorInterface et Cie , Reza 30/04/2009

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/TArray/utilarr.cc

    r3572 r3613  
    55#include "machdefs.h"
    66#include "utilarr.h"
    7 #include "stsrand.h"
     7#include "randr48.h"
    88
    99// Classe utilitaires
     
    2020*/
    2121
    22 //! Constructor
    23 /*!
    24   \param typ : generator type
    25   \param m : mean parameter of the generator (if needed)
    26   \param s : sigma parameter of the generator (if needed)
     22/*!
     23  \brief constructor using a global default random generator ( RandomGeneratorInterface::GetGlobalRandGenP() )
     24  \param typ : generated random numbers distribution type: C_RND_Flat,C_RND_Gaussian,C_RND_Poisson,C_RND_Exponential
     25  \param mean : mean value of the distribution
     26  \param sigma : standard deviation of the distribution
    2727 */
    28 static RandomGenerator* uarg_ = NULL;
    29 RandomSequence::RandomSequence(int typ, double m, double s)
    30 {
    31   typ_ = (typ == Flat) ? Flat : Gaussian;
    32   mean_ = m;
    33   sig_ = s;
    34   if (uarg_ == NULL) uarg_ = new RandomGenerator(1024, true);
    35 }
     28RandomSequence::RandomSequence(int typ, double mean, double sigma)
     29{
     30  typ_ = (typ == Flat) ? C_RND_Flat: C_RND_Gaussian ;
     31  mean_ = mean;
     32  sig_ = sigma;
     33  rgp_ = RandomGeneratorInterface::GetGlobalRandGenP();
     34}
     35
     36
     37/*!
     38  \brief constructor with the specification of a RandomGenerator object to be used.
     39  \param rgen : RandomGeneratorInterface object that should stay valid as long as the RandomSequence object exist.
     40  \param typ : generated random numbers distribution type: C_RND_Flat,C_RND_Gaussian,C_RND_Poisson,C_RND_Exponential
     41  \param mean : mean value of the distribution
     42  \param sigma : standard deviation of the distribution
     43 */
     44RandomSequence::RandomSequence(RandomGeneratorInterface& rgen, RNDTypes rtyp, double mean, double sigma)
     45{
     46  typ_ = rtyp;
     47  mean_ = mean;
     48  sig_ = sigma;
     49  rgp_ = &rgen;
     50}
     51
    3652RandomSequence::~RandomSequence()
    3753{
    3854}
    3955
    40 //! Return random sequence values.
    41 /*!
    42   \return If typ = Flat : return [-1,+1]*sig + mean
    43   \return If typ = Gaussian : return gaussian distributed
    44                           with \b mean mean and sigma \b sig
    45  */
    46 double RandomSequence::Rand()
    47 {
    48   if (typ_ == Flat)
    49     return(uarg_->Flatpm1()*sig_ + mean_);
    50   else return(uarg_->Gaussian(sig_, mean_));
    51 }
    52 
     56double RandomSequence::Next() const
     57{
     58  switch (typ_) {
     59    case C_RND_Flat :
     60      return rgp_->Flatpm1()*sig_ + mean_;
     61      break;
     62    case C_RND_Gaussian :
     63      return rgp_->Gaussian(sig_, mean_);
     64      break;
     65    case C_RND_Poisson :
     66      return rgp_->Poisson(mean_);
     67      break;
     68    case C_RND_Exponential :
     69      return rgp_->Exponential();
     70      break;
     71    default :
     72      return rgp_->Flat01();
     73      break;
     74
     75  }
     76}
     77
     78//!  \brief Return the next random number
    5379MuTyV & RandomSequence::Value(sa_size_t k) const
    5480{
    55   if (typ_ == Flat) retv_ = uarg_->Flatpm1()*sig_ + mean_;
    56   else retv_ = uarg_->Gaussian(sig_, mean_);
     81  retv_ = Next();
    5782  return retv_;
    5883}
Note: See TracChangeset for help on using the changeset viewer.