[3602] | 1 | #ifndef RANDR48_H_SEEN
|
---|
| 2 | #define RANDR48_H_SEEN
|
---|
| 3 |
|
---|
| 4 | // Classes DR48RandGen
|
---|
| 5 | // Generateur aleatoire utilisant l'aleatoire drand48()
|
---|
| 6 | //
|
---|
| 7 | // R. Ansari (C) UPS+LAL IN2P3/CNRS 2009
|
---|
| 8 | // C. Magneville (C) DAPNIA/SPP CEA 2009
|
---|
| 9 |
|
---|
| 10 |
|
---|
| 11 | #include "machdefs.h"
|
---|
| 12 | #include "objfio.h"
|
---|
| 13 | #include "ndatablock.h"
|
---|
| 14 | #include "randinterf.h"
|
---|
| 15 |
|
---|
[3615] | 16 |
|
---|
| 17 | /* ------- SPECIFIQUE Mac Darwin OSX <= 10.2 (gcc < 3.x) -------- */
|
---|
| 18 | #if defined(Darwin) && defined(__GNUC__) && (__GNUC__ < 3)
|
---|
| 19 | #include "osx_values.h"
|
---|
| 20 | /* Declaration de drand48 et srand48 etc , mis ds SysSpec, Reza 11/02/2003 */
|
---|
| 21 | #ifdef __cplusplus
|
---|
| 22 | extern "C" {
|
---|
| 23 | #endif
|
---|
| 24 | unsigned short int * seed48(unsigned short int seed16v[3]);
|
---|
| 25 | void srand48(long seedval);
|
---|
| 26 | #ifdef __cplusplus
|
---|
| 27 | }
|
---|
| 28 | #endif
|
---|
| 29 | #define drand48() ((double)(random())/LONG_MAX)
|
---|
| 30 | #endif
|
---|
| 31 | /* ------- FIN SPECIFIQUE Mac OSX / Darwin V <= 10.2 --------- */
|
---|
| 32 |
|
---|
| 33 |
|
---|
[3602] | 34 | namespace SOPHYA {
|
---|
| 35 |
|
---|
[3604] | 36 | //! Implementation of the RandomGeneratorInterface class using drand48() functions
|
---|
[3602] | 37 | class DR48RandGen : public RandomGeneratorInterface {
|
---|
| 38 |
|
---|
| 39 | public:
|
---|
[3739] | 40 | DR48RandGen();
|
---|
| 41 | DR48RandGen(long int seed);
|
---|
[3602] | 42 | virtual ~DR48RandGen();
|
---|
| 43 |
|
---|
| 44 | virtual void SetSeed(long int seed);
|
---|
| 45 | virtual void SetSeed(uint_2 seed[3]);
|
---|
| 46 | virtual void GetSeed(uint_2 seed[3]);
|
---|
| 47 | virtual void AutoInit(int lp=0);
|
---|
[3615] | 48 | virtual void ShowRandom();
|
---|
[3602] | 49 |
|
---|
| 50 | friend class ObjFileIO<DR48RandGen> ;
|
---|
| 51 |
|
---|
| 52 | protected:
|
---|
| 53 | virtual r_8 Next();
|
---|
| 54 |
|
---|
| 55 | };
|
---|
| 56 |
|
---|
[3612] | 57 |
|
---|
[3602] | 58 | //--------------------------------------------------------------------------------
|
---|
| 59 | //--------------------------------------------------------------------------------
|
---|
| 60 | //--------------------------------------------------------------------------------
|
---|
| 61 |
|
---|
[3604] | 62 | //! Version thread-safe de RandomGeneratorInterface avec drand48() functions
|
---|
[3602] | 63 | class ThSDR48RandGen : public DR48RandGen {
|
---|
| 64 |
|
---|
| 65 | public:
|
---|
| 66 | ThSDR48RandGen(size_t n=1024,bool tsafe=true);
|
---|
| 67 | ThSDR48RandGen(ThSDR48RandGen const & rg);
|
---|
| 68 | virtual ~ThSDR48RandGen();
|
---|
| 69 |
|
---|
| 70 | void SetBuffSize(size_t n);
|
---|
| 71 |
|
---|
| 72 | virtual void SetSeed(long int seed);
|
---|
| 73 | virtual void SetSeed(uint_2 seed[3]);
|
---|
| 74 | virtual void GetSeed(uint_2 seed[3]);
|
---|
| 75 | virtual void AutoInit(int lp=0);
|
---|
[3615] | 76 | virtual void ShowRandom();
|
---|
[3602] | 77 |
|
---|
| 78 | friend class ObjFileIO<ThSDR48RandGen> ;
|
---|
| 79 |
|
---|
| 80 | protected:
|
---|
| 81 | // ---- protected data members
|
---|
| 82 | NDataBlock<r_8> rseq_;
|
---|
| 83 | size_t idx_;
|
---|
| 84 | bool fg_nothrsafe; // if true --> NOT thread-safe
|
---|
| 85 | // ---- protected methods
|
---|
| 86 | void GenSeq();
|
---|
[3604] | 87 | virtual r_8 Next();
|
---|
| 88 |
|
---|
[3602] | 89 | // Non thread-safe version of Init() and GetSeed()
|
---|
| 90 | void SetSeed_P(uint_2 seed[3]);
|
---|
| 91 | void GetSeed_P(uint_2 seed[3]);
|
---|
| 92 |
|
---|
| 93 | };
|
---|
| 94 |
|
---|
| 95 | // Classe pour la gestion de persistance PPF : ObjFileIO<ThSDR48RandGen>
|
---|
| 96 |
|
---|
| 97 | /*! Writes the random generator object state in the POutPersist stream \b os */
|
---|
| 98 | inline POutPersist& operator << (POutPersist& os, ThSDR48RandGen & obj)
|
---|
| 99 | { ObjFileIO<ThSDR48RandGen> fio(&obj); fio.Write(os); return(os); }
|
---|
| 100 | /*! Reads the random generator object state from the PInPersist stream \b is */
|
---|
| 101 | inline PInPersist& operator >> (PInPersist& is, ThSDR48RandGen & obj)
|
---|
| 102 | { ObjFileIO<ThSDR48RandGen> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
|
---|
| 103 |
|
---|
| 104 | // Classe pour la gestion de persistance PPF : ObjFileIO<DR48RandGen>
|
---|
| 105 |
|
---|
| 106 | /*! Writes the random generator object state in the POutPersist stream \b os */
|
---|
| 107 | inline POutPersist& operator << (POutPersist& os, DR48RandGen & obj)
|
---|
| 108 | { ObjFileIO<DR48RandGen> fio(&obj); fio.Write(os); return(os); }
|
---|
| 109 | /*! Reads the random generator object state from the PInPersist stream \b is */
|
---|
| 110 | inline PInPersist& operator >> (PInPersist& is, DR48RandGen & obj)
|
---|
| 111 | { ObjFileIO<DR48RandGen> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
|
---|
| 112 |
|
---|
| 113 | } /* namespace SOPHYA */
|
---|
| 114 |
|
---|
| 115 | #endif
|
---|