#include #include #include "randtmt32.h" // pas definit en C++ (seulement en C) #ifndef UINT32_C # define UINT32_C(v) (v ## UL) #endif #include "tinymt32.h" namespace SOPHYA { //---------------------------------------------------------------- // Implementation d'un generateur aleatoire utilisant le code // Tiny Mersenne Twister (TinyMT). // http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html TinyMT32RandGen::TinyMT32RandGen(uint_4 seed) { // On est oblige de faire new car la structure tinymt32_t pas defini ds randtmt32.h tinymt32_ptr_ = new tinymt32_t; tinymt32_init(tinymt32_ptr_,seed); } TinyMT32RandGen::~TinyMT32RandGen() { // Ne pas oublier de faire le delete delete tinymt32_ptr_; } void TinyMT32RandGen::ShowRandom() { cout<<"RandomGenerator is TinyMT32RandGen"< seed) { if(seed.size()<=0) return; int key_length = (int)seed.size(); uint_4* init_key = new uint_4[key_length]; for(int i=0;i seed; GenerateSeedVector(1,seed,lp); vector s; uint_4 s4; s4 = uint_4(seed[0]) | (uint_4(seed[1])<<16); s.push_back(s4); s4 = uint_4(seed[2]) | (uint_4(seed[3])<<16); s.push_back(s4); SetSeed(s); } //---------------------------------------------------------- // Classe pour la gestion de persistance // ObjFileIO //---------------------------------------------------------- /* --Methode-- */ DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ void ObjFileIO::WriteSelf(POutPersist& s) const { if (dobj == NULL) throw NullPtrError("ObjFileIO::WriteSelf() dobj=NULL"); for(int i=0;i<4;i++)s.Put((uint_4)dobj->tinymt32_ptr_->status[i]); s.Put((uint_4)dobj->tinymt32_ptr_->mat1); s.Put((uint_4)dobj->tinymt32_ptr_->mat2); s.Put((uint_4)dobj->tinymt32_ptr_->tmat); return; } /* --Methode-- */ DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ void ObjFileIO::ReadSelf(PInPersist& s) { if(dobj == NULL) dobj = new TinyMT32RandGen(); uint_4 v; for(int i=0;i<4;i++) { s.Get(v); dobj->tinymt32_ptr_->status[i] = v; } s.Get(v); dobj->tinymt32_ptr_->mat1 = v; s.Get(v); dobj->tinymt32_ptr_->mat2 = v; s.Get(v); dobj->tinymt32_ptr_->tmat = v; return; } // --------------------------------------------------------- #ifdef __CXX_PRAGMA_TEMPLATES__ #pragma define_template ObjFileIO #endif #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) template class ObjFileIO; #endif } /* namespace SOPHYA */