Util/Random: Add randtime(Milliseconds const&, Milliseconds const&) to supersede urandms(uint32,uint32) for scripts being ported to std::chrono.

This commit is contained in:
treeston
2016-03-01 23:09:25 +01:00
parent 45c911ba94
commit 224b42c53a
2 changed files with 12 additions and 0 deletions

View File

@@ -61,6 +61,14 @@ float frand(float min, float max)
return float(GetRng()->Random() * (max - min) + min);
}
Milliseconds randtime(Milliseconds const& min, Milliseconds const& max)
{
long long diff = max.count() - min.count();
ASSERT(diff >= 0);
ASSERT(diff <= (uint32)-1);
return min + Milliseconds(urand(0, diff));
}
uint32 rand32()
{
return GetRng()->BRandom();

View File

@@ -19,6 +19,7 @@
#define Random_h__
#include "Define.h"
#include "Duration.h"
#include <limits>
#include <random>
@@ -34,6 +35,9 @@ uint32 urandms(uint32 min, uint32 max);
/* Return a random number in the range 0 .. UINT32_MAX. */
uint32 rand32();
/* Return a random time in the range min..max (up to millisecond precision). Only works for values where millisecond difference is a valid uint32. */
Milliseconds randtime(Milliseconds const& min, Milliseconds const& max);
/* Return a random number in the range min..max */
float frand(float min, float max);