Used effolkronium/random for PRNG

This commit is contained in:
2022-11-27 14:36:04 +02:00
parent d188b4d53f
commit 3a74dac29e
55 changed files with 434 additions and 518 deletions

View File

@ -1,6 +1,9 @@
#ifndef __INC_LIBTHECORE_UTILS_H__
#define __INC_LIBTHECORE_UTILS_H__
// Random number generator
#include "effolkronium/random.hpp"
using Random = effolkronium::random_static;
#define SAFE_FREE(p) { if (p) { free( (void *) p); (p) = NULL; } }
#define SAFE_DELETE(p) { if (p) { delete (p); (p) = NULL; } }
@ -45,13 +48,7 @@
extern int MIN(int a, int b); // <20><><EFBFBD>߿<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
extern int MINMAX(int min, int value, int max); // <20>ּ<EFBFBD> <20>ִ<EFBFBD> <20><><EFBFBD><EFBFBD> <20>Բ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD> <20><><EFBFBD><EFBFBD>
extern int number_ex(int from, int to, const char *file, int line); // from<6F><6D><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> to<74><6F><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>
#define number(from, to) number_ex(from, to, __FILE__, __LINE__)
float fnumber(float from, float to);
extern void thecore_sleep(struct timeval * timeout); // timeout<75><74>ŭ <20><><EFBFBD>μ<EFBFBD><CEBC><EFBFBD> <20><><EFBFBD><EFBFBD>
extern DWORD thecore_random(); // <20><><EFBFBD><EFBFBD> <20>Լ<EFBFBD>
extern float get_float_time();
extern DWORD get_dword_time();

View File

@ -345,42 +345,6 @@ int MINMAX(int min, int value, int max)
return (max < tv) ? max : tv;
}
DWORD thecore_random()
{
#ifdef __WIN32__
return rand();
#else
return random();
#endif
}
int number_ex(int from, int to, const char *file, int line)
{
if (from > to)
{
int tmp = from;
sys_err("number(): first argument is bigger than second argument %d -> %d, %s %d", from, to, file, line);
from = to;
to = tmp;
}
int returnValue = 0;
if ((to - from + 1) != 0)
returnValue = ((thecore_random() % (to - from + 1)) + from);
else
sys_err("number(): devided by 0");
return returnValue;
}
float fnumber(float from, float to)
{
return (((float)thecore_random() / (float)RAND_MAX) * (to - from)) + from;
}
#ifndef __WIN32__
void thecore_sleep(struct timeval* timeout)
{