Rev 671 | Rev 706 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 671 | Rev 705 | ||
---|---|---|---|
Line 28... | Line 28... | ||
28 | #define RAD(x) (x*M_PI/180.)
|
28 | #define RAD(x) (x*M_PI/180.)
|
29 | #define GRAD(x) (x/M_PI*180.)
|
29 | #define GRAD(x) (x/M_PI*180.)
|
30 | #define PI2 2*M_PI
|
30 | #define PI2 2*M_PI
|
31 | 31 | ||
32 | 32 | ||
33 | #include "globalsettings.h"
|
- | |
34 | #include "exception.h"
|
33 | #include "exception.h"
|
35 | // general datatypes
|
34 | // general datatypes
|
36 | //typedef int TreeSpecies;
|
35 | //typedef int TreeSpecies;
|
37 | 36 | ||
38 | // global debug helpers (used by macros!)
|
37 | // global debug helpers (used by macros!)
|
Line 72... | Line 71... | ||
72 | // log level functions
|
71 | // log level functions
|
73 | bool logLevelDebug(); // true, if detailed debug information is logged |
72 | bool logLevelDebug(); // true, if detailed debug information is logged |
74 | bool logLevelInfo(); // true, if only important aggreate info is logged |
73 | bool logLevelInfo(); // true, if only important aggreate info is logged |
75 | bool logLevelWarning(); // true if only severe warnings/errors are logged. |
74 | bool logLevelWarning(); // true if only severe warnings/errors are logged. |
76 | void setLogLevel(int loglevel); // setter function |
75 | void setLogLevel(int loglevel); // setter function |
- | 76 | // choose the random number generator:
|
|
- | 77 | // either:
|
|
77 | // cool random number generator (using the mersenne-twister) by http://www-personal.umich.edu/~wagnerr/MersenneTwister.html
|
78 | // cool random number generator (using the mersenne-twister) by http://www-personal.umich.edu/~wagnerr/MersenneTwister.html
|
78 | #include "../3rdparty/MersenneTwister.h"
|
- | |
79 | // access the Mersenne-Twister-Random-Numbers
|
- | |
80 | MTRand &mtRand(); // static object lives in globalsettings |
- | |
- | 79 | // #include "../3rdparty/MersenneTwister.h"
|
|
- | 80 | // or
|
|
- | 81 | #include "randomwell.h"
|
|
- | 82 | ||
- | 83 | MTRand *randomGenerator(); // static object lives in globalsettings |
|
81 | /// nrandom returns a random number from [p1, p2] -> p2 is a possible result!
|
84 | /// nrandom returns a random number from [p1, p2] -> p2 is a possible result!
|
82 | inline double nrandom(const double& p1, const double& p2) |
85 | inline double nrandom(const double& p1, const double& p2) |
83 | {
|
86 | {
|
84 | return p1 + mtRand().rand(p2-p1); |
- | |
- | 87 | return p1 + randomGenerator()->rand(p2-p1); |
|
85 | //return p1 + (p2-p1)*(rand()/double(RAND_MAX));
|
88 | //return p1 + (p2-p1)*(rand()/double(RAND_MAX));
|
86 | }
|
89 | }
|
87 | /// returns a random number in [0,1] (i.e.="1" is a possible result!)
|
90 | /// returns a random number in [0,1] (i.e.="1" is a possible result!)
|
88 | inline double drandom() |
91 | inline double drandom() |
89 | {
|
92 | {
|
90 | return mtRand().rand(); |
- | |
- | 93 | return randomGenerator()->rand(); |
|
91 | //return rand()/double(RAND_MAX);
|
94 | //return rand()/double(RAND_MAX);
|
92 | }
|
95 | }
|
93 | /// return a random number from "from" to "to" (incl.), i.e. irandom(3,5) results in 3, 4 or 5.
|
96 | /// return a random number from "from" to "to" (incl.), i.e. irandom(3,5) results in 3, 4 or 5.
|
94 | inline int irandom(int from, int to) |
97 | inline int irandom(int from, int to) |
95 | {
|
98 | {
|
96 | return from + mtRand().randInt(to-from); |
- | |
- | 99 | return from + randomGenerator()->randInt(to-from); |
|
97 | //return from + rand()%(to-from);
|
100 | //return from + rand()%(to-from);
|
98 | }
|
101 | }
|
99 | 102 | ||
100 | // random number function with additional ptr to random function
|
103 | // random number function with additional ptr to random function
|
101 | inline double nrandom(MTRand &random, const double& p1, const double& p2) |
- | |
- | 104 | inline double nrandom(MTRand *random, const double& p1, const double& p2) |
|
102 | {
|
105 | {
|
103 | return p1 + random.rand(p2-p1); |
- | |
- | 106 | return p1 + random->rand(p2-p1); |
|
104 | //return p1 + (p2-p1)*(rand()/double(RAND_MAX));
|
107 | //return p1 + (p2-p1)*(rand()/double(RAND_MAX));
|
105 | }
|
108 | }
|
106 | /// returns a random number in [0,1] (i.e.="1" is a possible result!)
|
109 | /// returns a random number in [0,1] (i.e.="1" is a possible result!)
|
107 | inline double drandom(MTRand &random) |
- | |
- | 110 | inline double drandom(MTRand *random) |
|
108 | {
|
111 | {
|
109 | return random.rand(); |
- | |
- | 112 | return random->rand(); |
|
110 | //return rand()/double(RAND_MAX);
|
113 | //return rand()/double(RAND_MAX);
|
111 | }
|
114 | }
|
112 | /// return a random number from "from" to "to" (incl.), i.e. irandom(3,5) results in 3, 4 or 5.
|
115 | /// return a random number from "from" to "to" (incl.), i.e. irandom(3,5) results in 3, 4 or 5.
|
113 | inline int irandom(MTRand &random, int from, int to) |
- | |
- | 116 | inline int irandom(MTRand *random, int from, int to) |
|
114 | {
|
117 | {
|
115 | return from + random.randInt(to-from); |
- | |
- | 118 | return from + random->randInt(to-from); |
|
116 | //return from + rand()%(to-from);
|
119 | //return from + rand()%(to-from);
|
117 | }
|
120 | }
|
118 | 121 | ||
119 | 122 | ||
120 | 123 | ||
Line 138... | Line 141... | ||
138 | return value & (1 << bit); |
141 | return value & (1 << bit); |
139 | }
|
142 | }
|
140 | 143 | ||
141 | // define a global isnan() function
|
144 | // define a global isnan() function
|
142 | #define isnan(x) ((x) != (x))
|
145 | #define isnan(x) ((x) != (x))
|
- | 146 | ||
- | 147 | #include "globalsettings.h"
|
|
143 | 148 | ||
144 | #endif // GLOBAL_H
|
149 | #endif // GLOBAL_H
|