StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DRand48Engine.h
1 /***************************************************************************
2  *
3  * $Id: DRand48Engine.h,v 1.1 1999/01/30 03:58:59 fisyak Exp $
4  *
5  * Author: Gabriele Cosmo - Created: 5th September 1995
6  * modified for SCL bl
7  ***************************************************************************
8  *
9  * Description:
10  * DRand48Engine.h,v 1.6 1998/02/02 10:05:05
11  * -----------------------------------------------------------------------
12  * HEP Random
13  * --- DRand48Engine ---
14  * class header file
15  * -----------------------------------------------------------------------
16  * This file is part of Geant4 (simulation toolkit for HEP).
17  *
18  * Random engine using drand48() and srand48() functions from C standard
19  * library to implement the flat() basic distribution and for setting
20  * seeds.
21  *
22  ***************************************************************************
23  *
24  * $Log: DRand48Engine.h,v $
25  * Revision 1.1 1999/01/30 03:58:59 fisyak
26  * Root Version of StarClassLibrary
27  *
28  * Revision 1.1 1999/01/23 00:27:32 ullrich
29  * Initial Revision
30  *
31  **************************************************************************/
32 #ifndef DRand48Engine_h
33 #define DRand48Engine_h 1
34 
35 #include "StGlobals.hh"
36 #include "RandomEngine.h"
37 #include <stdlib.h> // drand48() etc., tu
38 
39 #ifdef WIN32
40  // ********************************************************************
41  // Code extracted from GNU C Library 2.0.1
42 
43  /* Data structure for communication with thread safe versions. */
44  struct drand48_data
45  {
46  unsigned short int X[3]; /* Current state. */
47  unsigned short int a[3]; /* Factor in congruential formula. */
48  unsigned short int c; /* Additive const. in congruential formula. */
49  unsigned short int old_X[3]; /* Old state. */
50  int init; /* Flag for initializing. */
51  };
52 
53  /* Internal function to compute next state of the generator. */
54  extern "C" { int drand48_iterate (unsigned short int xsubi[3],
55  struct drand48_data *buffer); }
56 
57  /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
58  extern "C" { int drand48_r (struct drand48_data *buffer, double *result); }
59  extern "C" { int erand48_r (unsigned short int xsubi[3],
60  struct drand48_data *buffer, double *result); }
61 
62  /* Seed random number generator. */
63  extern "C" { int srand48_r (long seedval, struct drand48_data *buffer); }
64  extern "C" { int seed48_r (unsigned short int seed16v[3],
65  struct drand48_data *buffer); }
66 
67  /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
68  extern "C" { double drand48 (void); }
69  extern "C" { double erand48 (unsigned short int xsubi[3]); }
70 
71  /* Seed random number generator. */
72  extern "C" { void srand48 (long seedval); }
73  extern "C" { unsigned short int *seed48 (unsigned short int seed16v[3]); }
74 
75  // End Code extracted from GNU C Library 2.0.1
76  // ********************************************************************
77 #endif /* WIN32 */
78 
80 
81 public:
82 
83  DRand48Engine(long seed = 19780503);
84  ~DRand48Engine();
85  // Constructor and destructor
86 
87  DRand48Engine(const DRand48Engine &p);
88  // Copy constructor
89 
90  DRand48Engine & operator = (const DRand48Engine &p);
91  // Overloaded assignment operator, to retrieve the engine status.
92 
93  HepDouble flat();
94  // It returns a pseudo random number between 0 and 1,
95  // according to the standard stdlib random function drand48()
96  // but excluding the end points.
97 
98  void flatArray (const HepInt size, HepDouble* vect);
99 #ifndef ST_NO_TEMPLATE_DEF_ARGS
100  void flatArray (vector<HepDouble>&);
101 #else
102  void flatArray (vector<HepDouble, allocator<HepDouble> >&);
103 #endif
104  // Fills the array "vect" of specified size with flat random values.
105 
106  void setSeed(long seed, HepInt dum=0);
107  // Sets the state of the algorithm according to seed.
108 
109  void setSeeds(const long * seeds, HepInt dum=0);
110  // Sets the state of the algorithm according to the zero terminated
111  // array of seeds. Only the first seed is used.
112 
113  void saveStatus() const;
114  // Saves on file DRand48.conf the current engine status.
115 
116  void restoreStatus();
117  // Reads from file DRand48.conf the last saved engine status
118  // and restores it.
119 
120  void showStatus() const;
121  // Dumps the engine status on the screen.
122 
123 };
124 
125 #endif