Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef RANDOM_H
00030 #define RANDOM_H
00031
00032 #include <math.h>
00033
00034 #include "GaussDistribution.h"
00035 #include "Translations.h"
00036 #include "Trace.h"
00037
00038 namespace QGpCoreTools {
00039
00040 #define RANDOM_NTAB 32
00041 #define RANDOM_STATE_SIZE (RANDOM_NTAB+3)*sizeof(qint64)
00042
00043 class QGPCORETOOLS_EXPORT Random
00044 {
00045 TRANSLATIONS("Random")
00046 public:
00047 Random(int seed=0);
00048 Random(const QByteArray& s);
00049
00050 inline int uniform(int min, int max);
00051 inline double uniform(double min, double max);
00052 double normal(double mean, double stddev);
00053 double normal(GaussDistribution & gd) {return normal(gd.mean(),gd.stddev());}
00054 double ran2();
00055
00056 QByteArray state() const;
00057
00058 void testPeriod();
00059 void testDistribution(double max, qint64 nReset);
00060 private:
00061
00062 qint64 _idum;
00063 qint64 _idum2;
00064 qint64 _iy;
00065 qint64 _iv[RANDOM_NTAB];
00066 };
00067
00068 inline double Random::uniform(double min, double max)
00069 {
00070 return min+(max-min)*ran2();
00071 }
00072
00073 inline int Random::uniform(int min, int max)
00074 {
00075 return min+(int)round((max-min)*ran2());
00076 }
00077
00078 }
00079
00080 #endif // RANDOM_H