-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrnd.h
50 lines (39 loc) · 1.39 KB
/
rnd.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
50
#ifndef _RND_INCL
#define _RND_INCL
class RND
{
// Members: ********************************************
protected:
static double RndValue; // last "random" value
static double SeedValue; // gives first "random" value
static const double Multiplic; // constant for generator
static const double MaxLongD; // dto.
static const long MaxLong; // dto.
// Methods: ********************************************
// internal ]0, 1[ uniform generator *******************
double Rnd01()
{
double TmpValue
= (double)(long)(RndValue * MaxLongD + 0.5)
* Multiplic / MaxLongD;
RndValue = TmpValue - (double)(long)TmpValue;
return RndValue;
}
public:
// Con-/Destructor *************************************
RND() {}
virtual ~RND() {}
// Seed ************************************************
void SetSeedValue(long value);
long GetSeedValue() { return (long)(RndValue * MaxLongD + 0.5); }
// margins *********************************************
double GetMinRndValue() { return 1.0 / MaxLongD; }
double GetMaxRndValue() { return 1.0 - 1.0 / MaxLongD; }
// public generators ***********************************
virtual inline double Rnd() { return Rnd01(); }
virtual inline long RndL() { return -1; }
//*********************printseed..
void printseed(){ printf("Seed: %f\n",SeedValue); }
// default if generator makes no sense!
};
#endif