00001 /*************************************************************************** 00002 * 00003 * $Id: DRand48Engine.h,v 1.1 1999/01/30 03:58:59 fisyak Exp $ 00004 * 00005 * Author: Gabriele Cosmo - Created: 5th September 1995 00006 * modified for SCL bl 00007 *************************************************************************** 00008 * 00009 * Description: 00010 * DRand48Engine.h,v 1.6 1998/02/02 10:05:05 00011 * ----------------------------------------------------------------------- 00012 * HEP Random 00013 * --- DRand48Engine --- 00014 * class header file 00015 * ----------------------------------------------------------------------- 00016 * This file is part of Geant4 (simulation toolkit for HEP). 00017 * 00018 * Random engine using drand48() and srand48() functions from C standard 00019 * library to implement the flat() basic distribution and for setting 00020 * seeds. 00021 * 00022 *************************************************************************** 00023 * 00024 * $Log: DRand48Engine.h,v $ 00025 * Revision 1.1 1999/01/30 03:58:59 fisyak 00026 * Root Version of StarClassLibrary 00027 * 00028 * Revision 1.1 1999/01/23 00:27:32 ullrich 00029 * Initial Revision 00030 * 00031 **************************************************************************/ 00032 #ifndef DRand48Engine_h 00033 #define DRand48Engine_h 1 00034 00035 #include "StGlobals.hh" 00036 #include "RandomEngine.h" 00037 #include <stdlib.h> // drand48() etc., tu 00038 00039 #ifdef WIN32 00040 // ******************************************************************** 00041 // Code extracted from GNU C Library 2.0.1 00042 00043 /* Data structure for communication with thread safe versions. */ 00044 struct drand48_data 00045 { 00046 unsigned short int X[3]; /* Current state. */ 00047 unsigned short int a[3]; /* Factor in congruential formula. */ 00048 unsigned short int c; /* Additive const. in congruential formula. */ 00049 unsigned short int old_X[3]; /* Old state. */ 00050 int init; /* Flag for initializing. */ 00051 }; 00052 00053 /* Internal function to compute next state of the generator. */ 00054 extern "C" { int drand48_iterate (unsigned short int xsubi[3], 00055 struct drand48_data *buffer); } 00056 00057 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */ 00058 extern "C" { int drand48_r (struct drand48_data *buffer, double *result); } 00059 extern "C" { int erand48_r (unsigned short int xsubi[3], 00060 struct drand48_data *buffer, double *result); } 00061 00062 /* Seed random number generator. */ 00063 extern "C" { int srand48_r (long seedval, struct drand48_data *buffer); } 00064 extern "C" { int seed48_r (unsigned short int seed16v[3], 00065 struct drand48_data *buffer); } 00066 00067 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */ 00068 extern "C" { double drand48 (void); } 00069 extern "C" { double erand48 (unsigned short int xsubi[3]); } 00070 00071 /* Seed random number generator. */ 00072 extern "C" { void srand48 (long seedval); } 00073 extern "C" { unsigned short int *seed48 (unsigned short int seed16v[3]); } 00074 00075 // End Code extracted from GNU C Library 2.0.1 00076 // ******************************************************************** 00077 #endif /* WIN32 */ 00078 00079 class DRand48Engine : public HepRandomEngine { 00080 00081 public: 00082 00083 DRand48Engine(long seed = 19780503); 00084 ~DRand48Engine(); 00085 // Constructor and destructor 00086 00087 DRand48Engine(const DRand48Engine &p); 00088 // Copy constructor 00089 00090 DRand48Engine & operator = (const DRand48Engine &p); 00091 // Overloaded assignment operator, to retrieve the engine status. 00092 00093 HepDouble flat(); 00094 // It returns a pseudo random number between 0 and 1, 00095 // according to the standard stdlib random function drand48() 00096 // but excluding the end points. 00097 00098 void flatArray (const HepInt size, HepDouble* vect); 00099 #ifndef ST_NO_TEMPLATE_DEF_ARGS 00100 void flatArray (vector<HepDouble>&); 00101 #else 00102 void flatArray (vector<HepDouble, allocator<HepDouble> >&); 00103 #endif 00104 // Fills the array "vect" of specified size with flat random values. 00105 00106 void setSeed(long seed, HepInt dum=0); 00107 // Sets the state of the algorithm according to seed. 00108 00109 void setSeeds(const long * seeds, HepInt dum=0); 00110 // Sets the state of the algorithm according to the zero terminated 00111 // array of seeds. Only the first seed is used. 00112 00113 void saveStatus() const; 00114 // Saves on file DRand48.conf the current engine status. 00115 00116 void restoreStatus(); 00117 // Reads from file DRand48.conf the last saved engine status 00118 // and restores it. 00119 00120 void showStatus() const; 00121 // Dumps the engine status on the screen. 00122 00123 }; 00124 00125 #endif
1.5.9