mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
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:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user