adevs
adevs_rand.h
1 
31 #ifndef __adevs_rand_h_
32 #define __adevs_rand_h_
33 #include "adevs.h"
34 #include <cstdlib>
35 
36 namespace adevs
37 {
38 
39 typedef enum
40 {
41  NDURATION,
42  NCOUNT,EMPTY,
43  NDELAY,
44  ADDTOQ,
45  EMPTYQ,
46  HNCLMS,
47  HMODE,
48  PROBVAL,
49  ERRUNIFORM,
50  ERRNORMAL,
51  ERRLOGNORM,
52  ERRTRIANG,
53  ERRGAMMA,
54  ERRBETA,
55  ERREXPONENT,
56  ERRERLANG,
57  ERRHYPGEO,
58  NULLEV,
59  NOHISTO,
60  INITERR,
61  AMODE,
62  HFORM,
63  ERRFILE,
64  SAMPLE,
65  FRACTION,
66  LEVEL,
67  SCAN,
68  SUPPRESS,
69  SEED
70 } errorType;
71 
76 class random_seq
77 {
78  public:
80  virtual void set_seed(unsigned long seed) = 0;
82  virtual double next_dbl() = 0;
84  virtual random_seq* copy() const = 0;
86  virtual unsigned long next_long() = 0;
88  virtual ~random_seq(){}
89 };
90 
97 class crand: public random_seq
98 {
99  public:
101  crand():seedp(0){}
103  crand(const crand& src):seedp(src.seedp){}
105  crand(unsigned long seed):seedp((unsigned int)seed){}
107  void set_seed(unsigned long seed) { seedp = (unsigned int)seed; }
109  double next_dbl()
110  {
111  return ((double)next_long()/(double)RAND_MAX);
112  }
114  unsigned long next_long();
116  random_seq* copy() const { return new crand(*this); }
118  ~crand(){}
119  private:
120  unsigned int seedp;
121 };
122 
127 class rv
128 {
129  public:
131  rv (unsigned long seed = 1);
136  rv(random_seq* rand);
138  rv(const rv& src);
140  const rv& operator=(const rv& src);
142  void set_seed(unsigned long seed);
144  unsigned long next_long();
146  double triangular(double a, double b, double c);
148  double uniform(double a, double b);
153  double normal(double m, double s);
160  double exponential(double a);
161  double hyperexponential(double p,double a,double b);
162  double laplace(double a);
163  double chisquare(unsigned int n);
164  double student(unsigned int n);
165  double lognormal(double a,double b);
166  double erlang(unsigned int n,double a);
167  double gamma(double a,double b);
168  double beta(double a,double b);
169  double fdistribution(unsigned int n,unsigned int m);
170  double poisson(double a);
171  double geometric(double p);
172  double hypergeometric(unsigned int m,unsigned int n,double p);
173  double weibull(double a,double b);
174  double binomial(double p,unsigned int n);
175  double negativebinomial(double p,unsigned int n);
176  double triangular(double a);
177  int probability(double p);
178  double lngamma(double xx);
180  ~rv();
181  private:
182  random_seq* _impl;
183  void err(errorType n);
184 };
185 
186 } // end of namespace
187 
188 #endif
189 
190