/////////////////////////////////////////////////
//
// Template Image Processing System (TIPS)
//
// (c) 1997, Thomas F. El-Maraghi
//
// File:
//  random.h	
//
// Description:
//	Random number generator.
//
// Last modified:
//	18 August 1997
//
/////////////////////////////////////////////////


#ifndef _trandom_h
#define _trandom_h


/////////////////////////////////////////////////
// Random number generator


// The number of entries in the mSeedTable shuffle table
#define SEED_TABLE_SIZE 32


// Random numer generation class
class cRandom {
	long mSeed;
	long mSeedTable[SEED_TABLE_SIZE];
	long mNextSeed;
    bool fExtraGaussian;
    float ExtraGaussian;
        
public:
	// Construct a random number object with a specific seed
	cRandom( long number ) { Seed(number); fExtraGaussian = false; }

	// Construct a random number object with an automatic seed                       	
	cRandom() { Seed(); fExtraGaussian = false; }

	// Destroy a random number object
	~cRandom() {}

    // Seed the generator with a user provided number.
	void Seed( long number );

    // Seed the generator using the system clock.
	void Seed();

    // Get the next random number where the number
    // lies in the range (0,1)    
	float Uniform();

    // The Exponential() funciton returns the waiting time to the
    // next event of a Poisson distribution which has
    // Lambda events per second.
    float Exponential( float Lambda );   

    // Return a gaussian deviate with zero mean and unit variance
    float Gaussian();

    // Generate a random integer evenly distributed between
    // Min and Max (inclusive)
    int Integer( int Min, int Max ) { return (int)( (Uniform()*(Max-Min+1)) + Min ); }
};


/////////////////////////////////////////////////
// Global random number generator


#ifndef _trandom_cpp
extern cRandom Random;
#endif


#endif
