Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TRandomGen.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/mathcore:$Id$
0002 // Author: Rene Brun   04/03/99
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TRandomGen
0013 #define ROOT_TRandomGen
0014 
0015 
0016 
0017 //////////////////////////////////////////////////////////////////////////
0018 //                                                                      //
0019 // TRandomGen
0020 // @ingroup Random
0021 //                                                                      //
0022 // Generic random number generator class which is template on the type  //
0023 // of engine. Using this class different random number generator all    //
0024 // implementing the TRandom interface can be built.                     //
0025 // The available random number engine that can be presently used are    //
0026 //    * ROOT::Math::MixMaxEngine to create random number generators     //
0027 //       based on the MIXMAX family of generators. Different generators //
0028 //       can be created for different state N.                          //
0029 //    * ROOT::MATH::StdEngine to create genersators based on engines    //
0030 //      provided by the C++ standard libraries
0031 //
0032 //  Convenient typedef are defines to define the different types of
0033 //  generators. These typedef are
0034 //   * TRandomMixMax for the MixMaxEngine<240,0>  (MIXMAX with state N=240)
0035 //   * TRandomMixMax17 for the MixMaxEngine<17,0>  (MIXMAX with state N=17)
0036 //   * TRandomMixMax256 for the MixMaxEngine<256,2> (MIXMAX with state N=256 )
0037 //   * TRandomMT64 for the  StdEngine<std::mt19937_64> ( MersenneTwister 64 bits)
0038 //   * TRandomRanlux48 for the  StdEngine<std::ranlux48> (Ranlux 48 bits)
0039 //
0040 //                                                                     //
0041 //////////////////////////////////////////////////////////////////////////
0042 
0043 #include "TRandom.h"
0044 
0045 #include <string>
0046 
0047 template<class Engine>
0048 class TRandomGen : public TRandom {
0049 
0050 protected:
0051 
0052    Engine  fEngine;   // random number generator engine
0053 public:
0054 
0055    TRandomGen(ULong_t seed=1) {
0056       fEngine.SetSeed(seed);
0057       SetName(TString::Format("Random_%s", std::string(fEngine.Name()).c_str()));
0058       SetTitle(TString::Format("Random number generator: %s", std::string(fEngine.Name()).c_str()));
0059    }
0060    ~TRandomGen() override {}
0061    using TRandom::Rndm;
0062     Double_t Rndm( ) override { return fEngine(); }
0063     void     RndmArray(Int_t n, Float_t *array) override {
0064       for (int i = 0; i < n; ++i) array[i] = fEngine();
0065    }
0066     void     RndmArray(Int_t n, Double_t *array) override {
0067             for (int i = 0; i < n; ++i) array[i] = fEngine();
0068    }
0069     void     SetSeed(ULong_t seed=0) override {
0070       fEngine.SetSeed(seed);
0071    }
0072 
0073    ClassDefOverride(TRandomGen,1)  //Generic Random number generator template on the Engine type
0074 };
0075 
0076 // some useful typedef
0077 #include "Math/StdEngine.h"
0078 #include "Math/MixMaxEngine.h"
0079 #include "Math/RanluxppEngine.h"
0080 
0081 // not working wight now for this classes
0082 //#define  DEFINE_TEMPL_INSTANCE
0083 #ifdef DEFINE_TEMPL_INSTANCE
0084 
0085 extern template class  TRandomGen<ROOT::Math::MixMaxEngine<240,0>>;
0086 extern template class TRandomGen<ROOT::Math::MixMaxEngine<256,2>>;
0087 extern template class TRandomGen<ROOT::Math::MixMaxEngine<256,4>>;
0088 extern template class TRandomGen<ROOT::Math::MixMaxEngine<17,0>>;
0089 extern template class TRandomGen<ROOT::Math::MixMaxEngine<17,1>>;
0090 
0091 extern template class TRandomGen<ROOT::Math::RanluxppEngine2048>;
0092 
0093 extern template class  TRandomGen<ROOT::Math::StdEngine<std::mt19937_64> >;
0094 extern template class  TRandomGen<ROOT::Math::StdEngine<std::ranlux48> >;
0095 
0096 #endif
0097 /**
0098   @ingroup Random
0099   MIXMAX generator based on a state of N=240.
0100   This generator is described in this paper:
0101 
0102    K. Savvidy and G. Savvidy, *Spectrum and Entropy of C-systems. MIXMAX random number generator*,
0103   Chaos, Solitons & Fractals, Volume 91, (2016) pp. 33–38 http://dx.doi.org/10.1016/j.chaos.2016.05.003
0104  */
0105 typedef TRandomGen<ROOT::Math::MixMaxEngine<240,0>> TRandomMixMax;
0106 
0107 /**
0108   @ingroup Random
0109   MIXMAX generator based on a state of N=17. This generator has a fast seeding time
0110   compared to N=240.
0111    This generator is described in this paper:
0112 
0113    K. Savvidy and G. Savvidy, *Spectrum and Entropy of C-systems. MIXMAX random number generator*,
0114   Chaos, Solitons & Fractals, Volume 91, (2016) pp. 33–38 http://dx.doi.org/10.1016/j.chaos.2016.05.003
0115  */
0116 typedef TRandomGen<ROOT::Math::MixMaxEngine<17,0>> TRandomMixMax17;
0117 
0118 /**
0119   @ingroup Random
0120   MIXMAX generator based on a state of N=256, based on the generator described in this
0121   paper:
0122 
0123    K. Savvidy, *The MIXMAX random number generator*, Computer Physics Communications 196 (2015), pp 161–165
0124   http://dx.doi.org/10.1016/j.cpc.2015.06.003
0125 
0126    This generator has been implemented with a skipping value of 2 iterations (so retaining one
0127    matrix iteration every 3).
0128 
0129  */
0130 typedef TRandomGen<ROOT::Math::MixMaxEngine<256,2>> TRandomMixMax256;
0131 
0132 typedef TRandomGen<ROOT::Math::RanluxppEngine2048> TRandomRanluxpp;
0133 
0134 /**
0135   @ingroup Random
0136   Generator based on a the Mersenne-Twister generator with 64 bits,
0137   using the implementation provided by the standard library,
0138   std::mt19937_64 (see  http://www.cplusplus.com/reference/random/mt19937_64/ )
0139 
0140  */
0141 typedef TRandomGen<ROOT::Math::StdEngine<std::mt19937_64> > TRandomMT64;
0142 /**
0143   @ingroup Random
0144   Generator based on a the RanLux generator with 48 bits,
0145   using the implementation provided by the standard library,
0146   std::ranlux48 (see  http://www.cplusplus.com/reference/random/ranlux48/ )
0147 
0148  */
0149 typedef TRandomGen<ROOT::Math::StdEngine<std::ranlux48> > TRandomRanlux48;
0150 
0151 
0152 #endif