source: Sophya/trunk/SophyaLib/BaseTools/randr48.h@ 3603

Last change on this file since 3603 was 3602, checked in by cmv, 16 years ago

RandomGeneratorInterface + dSFMT etc..., cmv 28/04/2009

File size: 2.9 KB
Line 
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
16namespace SOPHYA {
17
18//! Pseudorandom number generator class using dSFMT code
19class DR48RandGen : public RandomGeneratorInterface {
20
21 public:
22 DR48RandGen(long int seed=12345);
23 virtual ~DR48RandGen();
24
25 virtual void SetSeed(long int seed);
26 virtual void SetSeed(uint_2 seed[3]);
27 virtual void GetSeed(uint_2 seed[3]);
28 virtual void AutoInit(int lp=0);
29
30 friend class ObjFileIO<DR48RandGen> ;
31
32 protected:
33 virtual r_8 Next();
34
35};
36
37//--------------------------------------------------------------------------------
38//--------------------------------------------------------------------------------
39//--------------------------------------------------------------------------------
40
41class ThSDR48RandGen : public DR48RandGen {
42
43 public:
44 ThSDR48RandGen(size_t n=1024,bool tsafe=true);
45 ThSDR48RandGen(ThSDR48RandGen const & rg);
46 virtual ~ThSDR48RandGen();
47
48 void SetBuffSize(size_t n);
49
50 virtual void SetSeed(long int seed);
51 virtual void SetSeed(uint_2 seed[3]);
52 virtual void GetSeed(uint_2 seed[3]);
53 virtual void AutoInit(int lp=0);
54
55 friend class ObjFileIO<ThSDR48RandGen> ;
56
57 protected:
58 // ---- protected data members
59 NDataBlock<r_8> rseq_;
60 size_t idx_;
61 bool fg_nothrsafe; // if true --> NOT thread-safe
62 // ---- protected methods
63 void GenSeq();
64 inline r_8 Next()
65 {
66 if (rseq_.Size() == 0) return drand48();
67 else {
68 if(idx_==rseq_.Size()) GenSeq();
69 return(rseq_(idx_++));
70 }
71 }
72 // Non thread-safe version of Init() and GetSeed()
73 void SetSeed_P(uint_2 seed[3]);
74 void GetSeed_P(uint_2 seed[3]);
75
76};
77
78// Classe pour la gestion de persistance PPF : ObjFileIO<ThSDR48RandGen>
79
80/*! Writes the random generator object state in the POutPersist stream \b os */
81inline POutPersist& operator << (POutPersist& os, ThSDR48RandGen & obj)
82{ ObjFileIO<ThSDR48RandGen> fio(&obj); fio.Write(os); return(os); }
83/*! Reads the random generator object state from the PInPersist stream \b is */
84inline PInPersist& operator >> (PInPersist& is, ThSDR48RandGen & obj)
85{ ObjFileIO<ThSDR48RandGen> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
86
87// Classe pour la gestion de persistance PPF : ObjFileIO<DR48RandGen>
88
89/*! Writes the random generator object state in the POutPersist stream \b os */
90inline POutPersist& operator << (POutPersist& os, DR48RandGen & obj)
91{ ObjFileIO<DR48RandGen> fio(&obj); fio.Write(os); return(os); }
92/*! Reads the random generator object state from the PInPersist stream \b is */
93inline PInPersist& operator >> (PInPersist& is, DR48RandGen & obj)
94{ ObjFileIO<DR48RandGen> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
95
96} /* namespace SOPHYA */
97
98#endif
Note: See TracBrowser for help on using the repository browser.