#ifndef __UTIL_H
#define __UTIL_H

#define PI        3.141592653589793
#define NUM_RANDOM_GENERATORS    32
#define INTRAND_MAX  0x7ffffffeL  /* = 2**31-2 */

//#define NULL 0

#define SIM_API					\


// random number generation (they use generator 0)
//
SIM_API void opp_randomize();         // init random number gen. with a random value
SIM_API long randseed();              // returns current seed
SIM_API long randseed(long seed);     // sets rndseed and returns old one
SIM_API int testrand();               // returns 1 if OK; keeps seed intact
SIM_API long intrand();               // in range 1..INTRAND_MAX
SIM_API long intrand(long r);         // in range 0..r-1  (OK if r<<INTRAND_MAX)
inline  double dblrand();             // in range 0.0..1.0

//
// another set of random number functions (using generator gen_nr)
//
SIM_API void genk_opp_randomize(int gen_nr);
SIM_API long genk_randseed(int gen_nr);
SIM_API long genk_randseed(int gen_nr, long seed);
SIM_API long genk_intrand(int gen_nr);
SIM_API long genk_intrand(int gen_nr,long r);
inline  double genk_dblrand(int gen_nr);

//
// distributions
//
// Argument types and return value must be `double' so that they can be used
// in NED files, and cPar 'F' and 'X' types.
//
SIM_API double uniform(double a, double b);
SIM_API double intuniform(double a, double b);
SIM_API double exponential(double p);
SIM_API double normal(double m, double d);
SIM_API double truncnormal(double m, double d);

SIM_API double genk_uniform(double gen_nr, double a, double b);
SIM_API double genk_intuniform(double gen_nr, double a, double b);
SIM_API double genk_exponential(double gen_nr, double p);
SIM_API double genk_normal(double gen_nr, double m, double d);
SIM_API double genk_truncnormal(double gen_nr, double m, double d);

inline double dblrand()
{
   return (double)intrand() / (double)((unsigned long)INTRAND_MAX+1UL);
}

inline double genk_dblrand(int gen_nr)
{
   return (double)genk_intrand(gen_nr) / (double)((unsigned long)INTRAND_MAX+1UL);
}
#endif
