refs #478 refs #488, utils / free functions

* seed for random numbers per thread
* added function to get all user metatypes as string
* added new read file function per path/name
* removed DBus operators for pixmap
* JSON operators for byte array
* util function for JSON string
This commit is contained in:
Klaus Basan
2015-10-14 01:48:52 +02:00
committed by Mathew Sutcliffe
parent 19df8a5d71
commit a725ce2181
14 changed files with 120 additions and 64 deletions

View File

@@ -8,6 +8,8 @@
*/
#include "blackmisc/math/mathutils.h"
#include <QThreadStorage>
#include <QTime>
#include <algorithm>
#include <cmath>
@@ -77,5 +79,19 @@ namespace BlackMisc
return (result >= 0.0) ? result : result + 360.0;
}
int CMathUtils::randomInteger(int low, int high)
{
static QThreadStorage<uint> seeds;
if (!seeds.hasLocalData())
{
// seed is per thread!
uint seed = static_cast<uint>(QTime::currentTime().msec());
qsrand(seed);
seeds.setLocalData(seed);
}
int r(qrand());
return r % ((high + 1) - low) + low;
}
} // namespace
} // namespace

View File

@@ -100,10 +100,7 @@ namespace BlackMisc
static double normalizeDegrees(double degrees);
//! Random number between low and high
static int randomInteger(int low, int high)
{
return qrand() % ((high + 1) - low) + low;
}
static int randomInteger(int low, int high);
};
} // namespace