File indexing completed on 2025-01-30 10:03:29
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 #ifndef MixMaxRng_h
0034 #define MixMaxRng_h 1
0035
0036 #include <array>
0037 #include <cstdint>
0038 #include "CLHEP/Random/defs.h"
0039 #include "CLHEP/Random/RandomEngine.h"
0040
0041 namespace CLHEP {
0042
0043
0044
0045
0046
0047
0048 using myID_t = std::uint32_t;
0049 using myuint_t = unsigned long long int;
0050
0051 class MixMaxRng: public HepRandomEngine {
0052
0053 static const int N = 17;
0054
0055 public:
0056
0057 MixMaxRng(std::istream& is);
0058 MixMaxRng();
0059 MixMaxRng(long seed);
0060 ~MixMaxRng();
0061
0062
0063 MixMaxRng(const MixMaxRng& rng);
0064 MixMaxRng& operator=(const MixMaxRng& rng);
0065
0066
0067 double flat() { return (S.counter<=(N-1)) ? generate(S.counter):iterate(); }
0068
0069
0070
0071
0072 void flatArray (const int size, double* vect);
0073
0074
0075 void setSeed(long seed, int dum=0);
0076
0077
0078 void setSeeds(const long * seeds, int seedNum=0);
0079
0080
0081
0082
0083
0084 void saveStatus( const char filename[] = "MixMaxRngState.conf" ) const;
0085
0086
0087 void restoreStatus( const char filename[] = "MixMaxRngState.conf" );
0088
0089
0090
0091 void showStatus() const;
0092
0093
0094 operator double();
0095
0096 operator float();
0097
0098 operator unsigned int();
0099
0100
0101 virtual std::ostream & put (std::ostream & os) const;
0102 virtual std::istream & get (std::istream & is);
0103 static std::string beginTag ( );
0104 virtual std::istream & getState ( std::istream & is );
0105
0106 std::string name() const { return "MixMaxRng"; }
0107 static std::string engineName();
0108
0109 std::vector<unsigned long> put () const;
0110 bool get (const std::vector<unsigned long> & v);
0111 bool getState (const std::vector<unsigned long> & v);
0112
0113 private:
0114
0115 static constexpr long long int SPECIAL = ((N==17)? 0 : ((N==240)? 487013230256099140ULL:0) );
0116 static constexpr long long int SPECIALMUL= ((N==17)? 36: ((N==240)? 51 :53) );
0117
0118 static constexpr int BITS=61;
0119 static constexpr myuint_t M61=2305843009213693951ULL;
0120 static constexpr double INV_M61=0.43368086899420177360298E-18;
0121 static constexpr unsigned int VECTOR_STATE_SIZE = 2*N+4;
0122
0123 #define MIXMAX_MOD_MERSENNE(k) ((((k)) & M61) + (((k)) >> BITS) )
0124
0125 static constexpr int rng_get_N();
0126 static constexpr long long int rng_get_SPECIAL();
0127 static constexpr int rng_get_SPECIALMUL();
0128 void seed_uniquestream( myID_t clusterID, myID_t machineID, myID_t runID, myID_t streamID );
0129 void seed_spbox(myuint_t);
0130 void print_state() const;
0131 myuint_t precalc();
0132 myuint_t get_next() ;
0133 inline double get_next_float() { return get_next_float_packbits(); }
0134
0135
0136 MixMaxRng Branch();
0137 void BranchInplace(int id);
0138
0139 MixMaxRng(myID_t clusterID, myID_t machineID, myID_t runID, myID_t streamID );
0140 inline void seed64(myuint_t seedval) { seed_uniquestream( 0, 0, (myID_t)(seedval>>32), (myID_t)seedval ); }
0141
0142 double generate(int i);
0143 double iterate();
0144
0145 double get_next_float_packbits();
0146 #if defined __GNUC__
0147 #pragma GCC diagnostic push
0148 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
0149 #pragma GCC diagnostic ignored "-Wuninitialized"
0150 #endif
0151 inline double convert1double(myuint_t u)
0152 {
0153 const double one = 1;
0154 const myuint_t onemask = *(myuint_t*)&one;
0155 myuint_t tmp = (u>>9) | onemask;
0156 double d = *(double*)&tmp;
0157 return d-1.0;
0158 }
0159 #if defined __GNUC__
0160 #pragma GCC diagnostic pop
0161 #endif
0162 myuint_t MOD_MULSPEC(myuint_t k);
0163 myuint_t MULWU(myuint_t k);
0164 void seed_vielbein( unsigned int i);
0165 myuint_t iterate_raw_vec(myuint_t* Y, myuint_t sumtotOld);
0166 myuint_t apply_bigskip(myuint_t* Vout, myuint_t* Vin, myID_t clusterID, myID_t machineID, myID_t runID, myID_t streamID );
0167 myuint_t modadd(myuint_t foo, myuint_t bar);
0168 #if defined(__x86_64__)
0169 myuint_t mod128(__uint128_t s);
0170 myuint_t fmodmulM61(myuint_t cum, myuint_t a, myuint_t b);
0171 #else
0172 myuint_t fmodmulM61(myuint_t cum, myuint_t s, myuint_t a);
0173 #endif
0174
0175 private:
0176
0177 struct rng_state_st
0178 {
0179 std::array<myuint_t, N> V;
0180 myuint_t sumtot;
0181 int counter;
0182 };
0183
0184 typedef struct rng_state_st rng_state_t;
0185 rng_state_t S;
0186 };
0187
0188 }
0189
0190 #endif