2020-03-22 00:45:04 +01:00
|
|
|
#pragma once
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include "SqBase.hpp"
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Attempt to generate a moderately unique number to be used as a seed for random numbers.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
uint32_t GenerateSeed();
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void ReseedRandom();
|
2021-01-30 07:51:39 +01:00
|
|
|
void ReseedRandom(uint32_t n);
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD int8_t GetRandomInt8();
|
|
|
|
SQMOD_NODISCARD int8_t GetRandomInt8(int8_t n);
|
|
|
|
SQMOD_NODISCARD int8_t GetRandomInt8(int8_t m, int8_t n);
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD uint8_t GetRandomUint8();
|
|
|
|
SQMOD_NODISCARD uint8_t GetRandomUint8(uint8_t n);
|
|
|
|
SQMOD_NODISCARD uint8_t GetRandomUint8(uint8_t m, uint8_t n);
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD int16_t GetRandomInt16();
|
|
|
|
SQMOD_NODISCARD int16_t GetRandomInt16(int16_t n);
|
|
|
|
SQMOD_NODISCARD int16_t GetRandomInt16(int16_t m, int16_t n);
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD uint16_t GetRandomUint16();
|
|
|
|
SQMOD_NODISCARD uint16_t GetRandomUint16(uint16_t n);
|
|
|
|
SQMOD_NODISCARD uint16_t GetRandomUint16(uint16_t m, uint16_t n);
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD int32_t GetRandomInt32();
|
|
|
|
SQMOD_NODISCARD int32_t GetRandomInt32(int32_t n);
|
|
|
|
SQMOD_NODISCARD int32_t GetRandomInt32(int32_t m, int32_t n);
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD uint32_t GetRandomUint32();
|
|
|
|
SQMOD_NODISCARD uint32_t GetRandomUint32(uint32_t n);
|
|
|
|
SQMOD_NODISCARD uint32_t GetRandomUint32(uint32_t m, uint32_t n);
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD int64_t GetRandomInt64();
|
|
|
|
SQMOD_NODISCARD int64_t GetRandomInt64(int64_t n);
|
|
|
|
SQMOD_NODISCARD int64_t GetRandomInt64(int64_t m, int64_t n);
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD uint64_t GetRandomUint64();
|
|
|
|
SQMOD_NODISCARD uint64_t GetRandomUint64(uint64_t n);
|
|
|
|
SQMOD_NODISCARD uint64_t GetRandomUint64(uint64_t m, uint64_t n);
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD float GetRandomFloat32();
|
|
|
|
SQMOD_NODISCARD float GetRandomFloat32(float n);
|
|
|
|
SQMOD_NODISCARD float GetRandomFloat32(float m, float n);
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD double GetRandomFloat64();
|
|
|
|
SQMOD_NODISCARD double GetRandomFloat64(double n);
|
|
|
|
SQMOD_NODISCARD double GetRandomFloat64(double m, double n);
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void GetRandomString(String & str, String::size_type len);
|
|
|
|
void GetRandomString(String & str, String::size_type len, String::value_type n);
|
|
|
|
void GetRandomString(String & str, String::size_type len, String::value_type m, String::value_type n);
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD bool GetRandomBool();
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T> struct RandomVal
|
|
|
|
{ /* ... */ };
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
template <> struct RandomVal< int8_t >
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
static inline int8_t Get() { return GetRandomInt8(); }
|
|
|
|
static inline int8_t Get(int8_t n) { return GetRandomInt8(n); }
|
|
|
|
static inline int8_t Get(int8_t m, int8_t n) { return GetRandomInt8(m, n); }
|
2016-02-20 23:25:00 +01:00
|
|
|
};
|
|
|
|
|
2021-01-30 07:51:39 +01:00
|
|
|
template <> struct RandomVal< uint8_t >
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
static inline uint8_t Get() { return GetRandomUint8(); }
|
|
|
|
static inline uint8_t Get(uint8_t n) { return GetRandomUint8(n); }
|
|
|
|
static inline uint8_t Get(uint8_t m, uint8_t n) { return GetRandomUint8(m, n); }
|
2016-02-20 23:25:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
template <> struct RandomVal< int16_t >
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
static inline int16_t Get() { return GetRandomInt16(); }
|
|
|
|
static inline int16_t Get(int16_t n) { return GetRandomInt16(n); }
|
|
|
|
static inline int16_t Get(int16_t m, int16_t n) { return GetRandomInt16(m, n); }
|
2016-02-20 23:25:00 +01:00
|
|
|
};
|
|
|
|
|
2021-01-30 07:51:39 +01:00
|
|
|
template <> struct RandomVal< uint16_t >
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
static inline uint16_t Get() { return GetRandomUint16(); }
|
|
|
|
static inline uint16_t Get(uint16_t n) { return GetRandomUint16(n); }
|
|
|
|
static inline uint16_t Get(uint16_t m, uint16_t n) { return GetRandomUint16(m, n); }
|
2016-02-20 23:25:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
template <> struct RandomVal< int32_t >
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
static inline int32_t Get() { return GetRandomInt32(); }
|
|
|
|
static inline int32_t Get(int32_t n) { return GetRandomInt32(n); }
|
|
|
|
static inline int32_t Get(int32_t m, int32_t n) { return GetRandomInt32(m, n); }
|
2016-02-20 23:25:00 +01:00
|
|
|
};
|
|
|
|
|
2021-01-30 07:51:39 +01:00
|
|
|
template <> struct RandomVal< uint32_t >
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
static inline uint32_t Get() { return GetRandomUint32(); }
|
|
|
|
static inline uint32_t Get(uint32_t n) { return GetRandomUint32(n); }
|
|
|
|
static inline uint32_t Get(uint32_t m, uint32_t n) { return GetRandomUint32(m, n); }
|
2016-02-20 23:25:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
template <> struct RandomVal< int64_t >
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
static inline int64_t Get() { return GetRandomInt64(); }
|
|
|
|
static inline int64_t Get(int64_t n) { return GetRandomInt64(n); }
|
|
|
|
static inline int64_t Get(int64_t m, int64_t n) { return GetRandomInt64(m, n); }
|
2016-02-20 23:25:00 +01:00
|
|
|
};
|
|
|
|
|
2021-01-30 07:51:39 +01:00
|
|
|
template <> struct RandomVal< uint64_t >
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
static inline uint64_t Get() { return GetRandomUint64(); }
|
|
|
|
static inline uint64_t Get(uint64_t n) { return GetRandomUint64(n); }
|
|
|
|
static inline uint64_t Get(uint64_t m, uint64_t n) { return GetRandomUint64(m, n); }
|
2016-02-20 23:25:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
template <> struct RandomVal< float >
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
static inline float Get() { return GetRandomFloat32(); }
|
|
|
|
static inline float Get(float n) { return GetRandomFloat32(n); }
|
|
|
|
static inline float Get(float m, float n) { return GetRandomFloat32(m, n); }
|
2016-02-20 23:25:00 +01:00
|
|
|
};
|
|
|
|
|
2021-01-30 07:51:39 +01:00
|
|
|
template <> struct RandomVal< double >
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
static inline double Get() { return GetRandomFloat64(); }
|
|
|
|
static inline double Get(double n) { return GetRandomFloat64(n); }
|
|
|
|
static inline double Get(double m, double n) { return GetRandomFloat64(m, n); }
|
2016-02-20 23:25:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <> struct RandomVal< bool >
|
|
|
|
{
|
|
|
|
static inline bool Get() { return GetRandomBool(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|