Rev 706 | Rev 779 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 706 | Rev 707 | ||
---|---|---|---|
Line 72... | Line 72... | ||
72 | // log level functions
|
72 | // log level functions
|
73 | bool logLevelDebug(); // true, if detailed debug information is logged |
73 | bool logLevelDebug(); // true, if detailed debug information is logged |
74 | bool logLevelInfo(); // true, if only important aggreate info is logged |
74 | bool logLevelInfo(); // true, if only important aggreate info is logged |
75 | bool logLevelWarning(); // true if only severe warnings/errors are logged. |
75 | bool logLevelWarning(); // true if only severe warnings/errors are logged. |
76 | void setLogLevel(int loglevel); // setter function |
76 | void setLogLevel(int loglevel); // setter function |
77 | // choose the random number generator:
|
- | |
78 | // either:
|
- | |
79 | // cool random number generator (using the mersenne-twister) by http://www-personal.umich.edu/~wagnerr/MersenneTwister.html
|
- | |
80 | #include "../3rdparty/MersenneTwister.h"
|
- | |
81 | // or
|
- | |
82 | //#include "randomwell.h"
|
- | |
83 | - | ||
84 | MTRand *randomGenerator(); // static object lives in globalsettings |
- | |
85 | /// nrandom returns a random number from [p1, p2] -> p2 is a possible result!
|
- | |
86 | inline double nrandom(const double& p1, const double& p2) |
- | |
87 | {
|
- | |
88 | return p1 + randomGenerator()->rand(p2-p1); |
- | |
89 | //return p1 + (p2-p1)*(rand()/double(RAND_MAX));
|
- | |
90 | }
|
- | |
91 | /// returns a random number in [0,1] (i.e.="1" is a possible result!)
|
- | |
92 | inline double drandom() |
- | |
93 | {
|
- | |
94 | return randomGenerator()->rand(); |
- | |
95 | //return rand()/double(RAND_MAX);
|
- | |
96 | }
|
- | |
97 | /// return a random number from "from" to "to" (incl.), i.e. irandom(3,5) results in 3, 4 or 5.
|
- | |
98 | inline int irandom(int from, int to) |
- | |
99 | {
|
- | |
100 | return from + randomGenerator()->randInt(to-from); |
- | |
101 | //return from + rand()%(to-from);
|
- | |
102 | }
|
- | |
103 | - | ||
104 | // random number function with additional ptr to random function
|
- | |
105 | inline double nrandom(MTRand *random, const double& p1, const double& p2) |
- | |
106 | {
|
- | |
107 | return p1 + random->rand(p2-p1); |
- | |
108 | //return p1 + (p2-p1)*(rand()/double(RAND_MAX));
|
- | |
109 | }
|
- | |
110 | /// returns a random number in [0,1] (i.e.="1" is a possible result!)
|
- | |
111 | inline double drandom(MTRand *random) |
- | |
112 | {
|
- | |
113 | return random->rand(); |
- | |
114 | //return rand()/double(RAND_MAX);
|
- | |
115 | }
|
- | |
116 | /// return a random number from "from" to "to" (incl.), i.e. irandom(3,5) results in 3, 4 or 5.
|
- | |
117 | inline int irandom(MTRand *random, int from, int to) |
- | |
118 | {
|
- | |
119 | return from + random->randInt(to-from); |
- | |
120 | //return from + rand()%(to-from);
|
- | |
121 | }
|
- | |
122 | 77 | ||
- | 78 | // the random number generator:
|
|
- | 79 | #include "randomgenerator.h"
|
|
123 | 80 | ||
124 | 81 | ||
125 | inline double limit(const double value, const double lower, const double upper) |
82 | inline double limit(const double value, const double lower, const double upper) |
126 | {
|
83 | {
|
127 | return qMax(qMin(value, upper), lower); |
84 | return qMax(qMin(value, upper), lower); |