-
Notifications
You must be signed in to change notification settings - Fork 5
/
rndunif.h
48 lines (37 loc) · 1.35 KB
/
rndunif.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef _RNDUNIF_INCL
#define _RNDUNIF_INCL
#include "rnd.h"
using namespace std;
class RNDUNIF: public RND
{
// Members: ********************************************
//private:
double MinValue; // lower bound
double MaxValue; // upper bound
double DiffValue; // difference of bounds
double Mean; // theoretical mean/expectation
double Var; // theoretical variance
// Methods: ********************************************
public:
// Constructor *****************************************
RNDUNIF(double minval, double maxval)
// RNDUNIF::RNDUNIF(double minval, double maxval)
{
MinValue = minval;
MaxValue = maxval;
DiffValue = MaxValue - MinValue;
Mean = 0.5 * (MinValue + MaxValue);
Var = DiffValue * DiffValue / 12.0;
}
// margins *********************************************
double GetMinRndValue()
{ return DiffValue * RND::GetMinRndValue() + MinValue; }
double GetMaxRndValue()
{ return DiffValue * RND::GetMaxRndValue() + MinValue; }
// public generators **********************************
virtual inline double Rnd()
{ return DiffValue * Rnd01() + MinValue; }
// friend: output operator *****************************
friend ostream& operator<<(ostream& outp, RNDUNIF& gen);
};
#endif