-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrndunid.h
49 lines (41 loc) · 1.44 KB
/
rndunid.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
49
#ifndef _RNDUNID_INCL
#define _RNDUNID_INCL
#include "rnd.h"
using namespace std;
class RNDUNID: public RND
{
// Members: ********************************************
private:
double MinValue; // smallest value
double MaxValue; // largest value
double DiffValue; // difference + 1
double Mean; // theoretical mean/expectation
double Var; // theoretical variance
// Methods: ********************************************
public:
// Constructor *****************************************
RNDUNID(double minval, double maxval)
{
MinValue = floor(minval + 0.5);
MaxValue = floor(maxval + 0.5);
DiffValue = MaxValue - MinValue + 1.0;
Mean = 0.5 * (MaxValue + MinValue);
Var = (DiffValue * DiffValue - 1.0) / 12.0;
}
// margins *********************************************
double GetMinRndValue()
{ return floor(DiffValue * RND::GetMinRndValue() + 1e-11)
+ MinValue; }
double GetMaxRndValue()
{ return floor(DiffValue * RND::GetMaxRndValue() + 1e-11)
+ MinValue; }
// public generators ***********************************
virtual inline double Rnd()
{ return floor(DiffValue * Rnd01() + 1e-11) + MinValue; }
virtual inline long RndL()
{ return (long)(DiffValue * Rnd01() + MinValue + 1e-11); }
//*********************printseed..
// friend: output operator *****************************
friend ostream& operator<<(ostream& outp, RNDUNID& gen);
};
#endif