mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 00:16:51 +08:00
* 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:
committed by
Mathew Sutcliffe
parent
19df8a5d71
commit
a725ce2181
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user