Changeset 3612 in Sophya for trunk/SophyaLib/BaseTools/stsrand.cc
- Timestamp:
- Apr 30, 2009, 7:06:50 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/stsrand.cc
r3599 r3612 9 9 10 10 /*! 11 \class RandomGenerator11 \class STSRandGen 12 12 \ingroup BaseTools 13 13 \brief Random number generator … … 17 17 random number generator used. 18 18 19 \sa SOPHYA::ObjFileIO< RandomGenerator>19 \sa SOPHYA::ObjFileIO<STSRandGen> 20 20 21 21 \sa frand01 drand01 frandpm1 drandpm1 … … 29 29 static ThSafeOp* ths_rand = NULL; 30 30 31 RandomGenerator::RandomGenerator(size_t n, bool tsafe)31 STSRandGen::STSRandGen(size_t n, bool tsafe) 32 32 { 33 33 if (ths_rand == NULL) ths_rand = new ThSafeOp; … … 44 44 } 45 45 46 RandomGenerator::RandomGenerator(RandomGeneratorconst & rg)46 STSRandGen::STSRandGen(STSRandGen const & rg) 47 47 { 48 48 if (ths_rand == NULL) ths_rand = new ThSafeOp; … … 59 59 60 60 61 RandomGenerator::~RandomGenerator(void)61 STSRandGen::~STSRandGen(void) 62 62 { 63 63 // rien a faire 64 64 } 65 65 66 void RandomGenerator::SetBuffSize(size_t n)66 void STSRandGen::SetBuffSize(size_t n) 67 67 // redimensionnement du buffer 68 68 { … … 73 73 } 74 74 75 void RandomGenerator::AutoInit(int lp)75 void STSRandGen::AutoInit(int lp) 76 76 // Initialisation automatique (pseudo) aleatoire du generateur. 77 77 // L'initialiseur est donne par un codage du nombre de millisecondes … … 133 133 } 134 134 } 135 if(lp>0) cout<<" RandomGenerator::AutoInit: "<<seed_16v[0]<<" "<<seed_16v[1]<<" "<<seed_16v[2]<<endl;135 if(lp>0) cout<<"STSRandGen::AutoInit: "<<seed_16v[0]<<" "<<seed_16v[1]<<" "<<seed_16v[2]<<endl; 136 136 137 137 // Initialise drand48() … … 139 139 } 140 140 141 void RandomGenerator::Init(long seed_val, int lp)142 { 143 if (ths_rand == NULL) ths_rand = new ThSafeOp; 144 if(lp) cout << " RandomGenerator::Init(long seed=" << seed_val << ")" << endl;141 void STSRandGen::Init(long seed_val, int lp) 142 { 143 if (ths_rand == NULL) ths_rand = new ThSafeOp; 144 if(lp) cout << "STSRandGen::Init(long seed=" << seed_val << ")" << endl; 145 145 ths_rand->lock(); 146 146 srand48(seed_val); … … 149 149 } 150 150 151 void RandomGenerator::Init(unsigned short seed_16v[3], int lp)152 { 153 if (ths_rand == NULL) ths_rand = new ThSafeOp; 154 if(lp) cout << " RandomGenerator::Init(u_short seed_16v[3]=" << seed_16v[0]151 void STSRandGen::Init(unsigned short seed_16v[3], int lp) 152 { 153 if (ths_rand == NULL) ths_rand = new ThSafeOp; 154 if(lp) cout << "STSRandGen::Init(u_short seed_16v[3]=" << seed_16v[0] 155 155 << "," << seed_16v[1] << "," << seed_16v[2] << ")" << endl; 156 156 ths_rand->lock(); … … 159 159 } 160 160 161 void RandomGenerator::GetSeed(unsigned short seed_16v[3], int lp)161 void STSRandGen::GetSeed(unsigned short seed_16v[3], int lp) 162 162 { 163 163 if (ths_rand == NULL) ths_rand = new ThSafeOp; … … 165 165 GetSeed_P(seed_16v); 166 166 ths_rand->unlock(); 167 if(lp) cout << " RandomGenerator::GetSeed(u_short seed_16v[3]=" << seed_16v[0]167 if(lp) cout << "STSRandGen::GetSeed(u_short seed_16v[3]=" << seed_16v[0] 168 168 << "," << seed_16v[1] << "," << seed_16v[2] << ")" << endl; 169 169 return; 170 170 } 171 171 172 void RandomGenerator::Init_P(unsigned short seed_16v[3])172 void STSRandGen::Init_P(unsigned short seed_16v[3]) 173 173 { 174 174 seed48(seed_16v); 175 175 } 176 176 177 void RandomGenerator::GetSeed_P(unsigned short seed_16v[3])177 void STSRandGen::GetSeed_P(unsigned short seed_16v[3]) 178 178 { 179 179 unsigned short seed[3] = {0,0,0}; … … 186 186 } 187 187 188 r_8 RandomGenerator::Gaussian()188 r_8 STSRandGen::Gaussian() 189 189 { 190 190 r_8 A=Next(); … … 194 194 195 195 196 uint_8 RandomGenerator::Poisson(double mu,double mumax)196 uint_8 STSRandGen::Poisson(double mu,double mumax) 197 197 { 198 198 double pp,ppi,x; … … 218 218 } 219 219 220 void RandomGenerator::GenSeq(void)220 void STSRandGen::GenSeq(void) 221 221 { 222 222 ths_rand->lock(); … … 228 228 //---------------------------------------------------------- 229 229 // Classe pour la gestion de persistance 230 // ObjFileIO< RandomGenerator>230 // ObjFileIO<STSRandGen> 231 231 //---------------------------------------------------------- 232 232 233 233 /* --Methode-- */ 234 234 DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ 235 void ObjFileIO< RandomGenerator>::WriteSelf(POutPersist& s) const235 void ObjFileIO<STSRandGen>::WriteSelf(POutPersist& s) const 236 236 { 237 237 if (dobj == NULL) 238 throw NullPtrError("ObjFileIO< RandomGenerator>::WriteSelf() dobj=NULL");238 throw NullPtrError("ObjFileIO<STSRandGen>::WriteSelf() dobj=NULL"); 239 239 ths_rand->lock(); // thread-safety 240 240 uint_4 itab[6]; … … 259 259 /* --Methode-- */ 260 260 DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ 261 void ObjFileIO< RandomGenerator>::ReadSelf(PInPersist& s)261 void ObjFileIO<STSRandGen>::ReadSelf(PInPersist& s) 262 262 { 263 263 uint_4 itab[6]; … … 268 268 s.Get(ix); // Taille du tableau intermediaire 269 269 270 if (dobj == NULL) dobj = new RandomGenerator(sz, (sz>0)?true:false);270 if (dobj == NULL) dobj = new STSRandGen(sz, (sz>0)?true:false); 271 271 dobj->idx_ = ix; 272 272 if (sz > 0) { … … 288 288 // --------------------------------------------------------- 289 289 #ifdef __CXX_PRAGMA_TEMPLATES__ 290 #pragma define_template ObjFileIO< RandomGenerator>290 #pragma define_template ObjFileIO<STSRandGen> 291 291 #endif 292 292 293 293 #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) 294 template class ObjFileIO< RandomGenerator>;294 template class ObjFileIO<STSRandGen>; 295 295 #endif 296 296 // ---------------------------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.