37 #ifndef EGS_RANDOM_GENERATOR_
38 #define EGS_RANDOM_GENERATOR_
105 fillArray(np,rarray);
126 return ip<np ? count - np + ip : count;
140 register EGS_Float xphi,xphi2,yphi,yphi2,rhophi;
142 xphi = 2*getUniform() - 1;
146 rhophi = xphi2 + yphi2;
149 cphi = (xphi2 - yphi2)/rhophi;
150 sphi = 2*xphi*yphi/rhophi;
152 EGS_Float phi = 2*M_PI*getUniform();
166 EGS_Float r = sqrt(-2*log(1-getUniform()));
167 EGS_Float cphi, sphi;
168 getAzimuth(cphi,sphi);
227 bool storeState(ostream &data);
228 bool setState(istream &data);
229 bool addState(istream &data);
230 void resetCounter() {
287 void allocate(
int n);
291 return 2*
sizeof(EGS_I32) +
sizeof(EGS_I64) +
sizeof(bool) +
292 sizeof(EGS_Float) + np*
sizeof(EGS_Float);
Base random number generator class. All random number generators should be derived from this class.
virtual void fillArray(int n, EGS_Float *array)=0
Fill the array of n elements pointed to by array with random numbers.
void getAzimuth(EGS_Float &cphi, EGS_Float &sphi)
Sets cphi and sphi to the cosine and sine of a random angle uniformely distributed between 0 and .
EGS_RandomGenerator(const EGS_RandomGenerator &r)
Copy constructor.
int baseSize() const
The memory needed to store the base state.
virtual bool storePrivateState(ostream &data)=0
Store the state of the RNG to the output stream data.
virtual void setState(EGS_RandomGenerator *r)=0
Set the state of the RNG from another RNG.
virtual void saveState()=0
Save the RNG state.
EGS_Float getGaussian()
Returns a Gaussian distributed random number with mean zero and standard deviation 1.
virtual void describeRNG() const
Describe this RNG.
virtual int rngSize() const =0
The memory needed to store the rng state.
int np
size of the array rarray
int ip
pointer to the next rarray element in the sequence
EGS_I64 numbersUsed() const
Returns the number of random numbers used so far.
EGS_Float getUniform()
Returns a random number uniformly distributed between zero (inclusive) and 1 (exclusive).
virtual bool setPrivateState(istream &data)=0
Set the state of the RNG object from the data in the input stream data.
virtual ~EGS_RandomGenerator()
Destructor.
virtual EGS_RandomGenerator * getCopy()=0
Get a copy of the RNG.
EGS_I64 numbersGenerated() const
Returns the number of random numbers generated so far.
virtual void resetState()=0
Reset the state to a previously saved state.
EGS_I64 count
random number generated so far
EGS_Float * rarray
array with random numbers of size np.
Global egspp functions header file.
Defines the EGS_EXPORT and EGS_LOCAL macros.
#define EGS_EXPORT
Export symbols from the egspp library.
Attempts to fix broken math header files.