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

Last change on this file since 3820 was 3739, checked in by ansari, 16 years ago

suppression init systematique (setseed) de drand48() ds le contructeur de DR48RandGen, cmv+reza 04/02/2010

File size: 3.5 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
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
22extern "C" {
23#endif
24unsigned short int * seed48(unsigned short int seed16v[3]);
25void 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
34namespace SOPHYA {
35
36//! Implementation of the RandomGeneratorInterface class using drand48() functions
37class DR48RandGen : public RandomGeneratorInterface {
38
39 public:
40 DR48RandGen();
41 DR48RandGen(long int seed);
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);
48 virtual void ShowRandom();
49
50 friend class ObjFileIO<DR48RandGen> ;
51
52 protected:
53 virtual r_8 Next();
54
55};
56
57
58//--------------------------------------------------------------------------------
59//--------------------------------------------------------------------------------
60//--------------------------------------------------------------------------------
61
62//! Version thread-safe de RandomGeneratorInterface avec drand48() functions
63class 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);
76 virtual void ShowRandom();
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();
87 virtual r_8 Next();
88
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 */
98inline 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 */
101inline 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 */
107inline 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 */
110inline 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
Note: See TracBrowser for help on using the repository browser.