00001
00031 #ifndef __adevs_rand_h_
00032 #define __adevs_rand_h_
00033 #include "adevs.h"
00034 #include <cstdlib>
00035
00036 namespace adevs
00037 {
00038
00039 typedef enum
00040 {
00041 NDURATION,
00042 NCOUNT,EMPTY,
00043 NDELAY,
00044 ADDTOQ,
00045 EMPTYQ,
00046 HNCLMS,
00047 HMODE,
00048 PROBVAL,
00049 ERRUNIFORM,
00050 ERRNORMAL,
00051 ERRLOGNORM,
00052 ERRTRIANG,
00053 ERRGAMMA,
00054 ERRBETA,
00055 ERREXPONENT,
00056 ERRERLANG,
00057 ERRHYPGEO,
00058 NULLEV,
00059 NOHISTO,
00060 INITERR,
00061 AMODE,
00062 HFORM,
00063 ERRFILE,
00064 SAMPLE,
00065 FRACTION,
00066 LEVEL,
00067 SCAN,
00068 SUPPRESS,
00069 SEED
00070 } errorType;
00071
00076 class random_seq
00077 {
00078 public:
00080 virtual void set_seed(unsigned long seed) = 0;
00082 virtual double next_dbl() = 0;
00084 virtual random_seq* copy() const = 0;
00086 virtual unsigned long next_long() = 0;
00088 virtual ~random_seq(){}
00089 };
00090
00097 class crand: public random_seq
00098 {
00099 public:
00101 crand():seedp(0){}
00103 crand(const crand& src):seedp(src.seedp){}
00105 crand(unsigned long seed):seedp((unsigned int)seed){}
00107 void set_seed(unsigned long seed) { seedp = (unsigned int)seed; }
00109 double next_dbl()
00110 {
00111 return ((double)next_long()/(double)RAND_MAX);
00112 }
00114 unsigned long next_long();
00116 random_seq* copy() const { return new crand(*this); }
00118 ~crand(){}
00119 private:
00120 unsigned int seedp;
00121 };
00122
00127 class rv
00128 {
00129 public:
00131 rv (unsigned long seed = 1);
00136 rv(random_seq* rand);
00138 rv(const rv& src);
00140 const rv& operator=(const rv& src);
00142 void set_seed(unsigned long seed);
00144 unsigned long next_long();
00147 double triangular(double a, double b, double c);
00149 double uniform(double a, double b);
00154 double normal(double m, double s);
00161 double exponential(double a);
00162 double hyperexponential(double p,double a,double b);
00163 double laplace(double a);
00164 double chisquare(unsigned int n);
00165 double student(unsigned int n);
00166 double lognormal(double a,double b);
00167 double erlang(unsigned int n,double a);
00168 double gamma(double a,double b);
00169 double beta(double a,double b);
00170 double fdistribution(unsigned int n,unsigned int m);
00171 double poisson(double a);
00172 double geometric(double p);
00173 double hypergeometric(unsigned int m,unsigned int n,double p);
00174 double weibull(double a,double b);
00175 double binomial(double p,unsigned int n);
00176 double negativebinomial(double p,unsigned int n);
00177 double triangular(double a);
00178 int probability(double p);
00179 double lngamma(double xx);
00181 ~rv();
00182 private:
00183 random_seq* _impl;
00184 void err(errorType n);
00185 };
00186
00187 }
00188
00189 #endif
00190
00191