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

Last change on this file since 3670 was 3615, checked in by cmv, 16 years ago

Modifs relatives a l'introduction de RandomGeneratorInterface + delete de srandgen.c, cmv 01/05/2009

File size: 3.4 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(long int seed=12345);
41 virtual ~DR48RandGen();
42
43 virtual void SetSeed(long int seed);
44 virtual void SetSeed(uint_2 seed[3]);
45 virtual void GetSeed(uint_2 seed[3]);
46 virtual void AutoInit(int lp=0);
47 virtual void ShowRandom();
48
49 friend class ObjFileIO<DR48RandGen> ;
50
51 protected:
52 virtual r_8 Next();
53
54};
55
56
57//--------------------------------------------------------------------------------
58//--------------------------------------------------------------------------------
59//--------------------------------------------------------------------------------
60
61//! Version thread-safe de RandomGeneratorInterface avec drand48() functions
62class ThSDR48RandGen : public DR48RandGen {
63
64 public:
65 ThSDR48RandGen(size_t n=1024,bool tsafe=true);
66 ThSDR48RandGen(ThSDR48RandGen const & rg);
67 virtual ~ThSDR48RandGen();
68
69 void SetBuffSize(size_t n);
70
71 virtual void SetSeed(long int seed);
72 virtual void SetSeed(uint_2 seed[3]);
73 virtual void GetSeed(uint_2 seed[3]);
74 virtual void AutoInit(int lp=0);
75 virtual void ShowRandom();
76
77 friend class ObjFileIO<ThSDR48RandGen> ;
78
79 protected:
80 // ---- protected data members
81 NDataBlock<r_8> rseq_;
82 size_t idx_;
83 bool fg_nothrsafe; // if true --> NOT thread-safe
84 // ---- protected methods
85 void GenSeq();
86 virtual r_8 Next();
87
88 // Non thread-safe version of Init() and GetSeed()
89 void SetSeed_P(uint_2 seed[3]);
90 void GetSeed_P(uint_2 seed[3]);
91
92};
93
94// Classe pour la gestion de persistance PPF : ObjFileIO<ThSDR48RandGen>
95
96/*! Writes the random generator object state in the POutPersist stream \b os */
97inline POutPersist& operator << (POutPersist& os, ThSDR48RandGen & obj)
98{ ObjFileIO<ThSDR48RandGen> fio(&obj); fio.Write(os); return(os); }
99/*! Reads the random generator object state from the PInPersist stream \b is */
100inline PInPersist& operator >> (PInPersist& is, ThSDR48RandGen & obj)
101{ ObjFileIO<ThSDR48RandGen> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
102
103// Classe pour la gestion de persistance PPF : ObjFileIO<DR48RandGen>
104
105/*! Writes the random generator object state in the POutPersist stream \b os */
106inline POutPersist& operator << (POutPersist& os, DR48RandGen & obj)
107{ ObjFileIO<DR48RandGen> fio(&obj); fio.Write(os); return(os); }
108/*! Reads the random generator object state from the PInPersist stream \b is */
109inline PInPersist& operator >> (PInPersist& is, DR48RandGen & obj)
110{ ObjFileIO<DR48RandGen> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
111
112} /* namespace SOPHYA */
113
114#endif
Note: See TracBrowser for help on using the repository browser.