fix rand() misuse

This commit is contained in:
Silent 2017-03-09 00:53:03 +01:00
parent 2e82d001e1
commit cffabce8ab
3 changed files with 5 additions and 4 deletions

View file

@ -786,10 +786,10 @@ int NewFrameRender(int nEvent, void* pParam)
#include <ctime> #include <ctime>
#include <random> #include <random>
int Int32Rand() static std::ranlux48 generator (time(nullptr));
int32_t Int32Rand()
{ {
static std::ranlux48 generator (time(nullptr)); return generator() & INT32_MAX;
return generator() & 0x7FFFFFFF;
} }
void (*FlushSpriteBuffer)() = AddressByVersion<void(*)()>(0x70CF20, 0x70D750, 0x7591E0, 0x753AE0, 0x753A00); void (*FlushSpriteBuffer)() = AddressByVersion<void(*)()>(0x70CF20, 0x70D750, 0x7591E0, 0x753AE0, 0x753A00);

View file

@ -30,6 +30,7 @@
extern void (*GTAdelete)(void* data); extern void (*GTAdelete)(void* data);
extern const char* (*GetFrameNodeName)(RwFrame*); extern const char* (*GetFrameNodeName)(RwFrame*);
extern RpHAnimHierarchy* (*GetAnimHierarchyFromSkinClump)(RpClump*); extern RpHAnimHierarchy* (*GetAnimHierarchyFromSkinClump)(RpClump*);
int32_t Int32Rand();
extern unsigned char& nGameClockDays; extern unsigned char& nGameClockDays;
extern unsigned char& nGameClockMonths; extern unsigned char& nGameClockMonths;

View file

@ -19,7 +19,7 @@ WRAPPER bool CVehicle::IsLawEnforcementVehicle() { VARJMP(varIsLawEnforcementVeh
static int32_t random(int32_t from, int32_t to) static int32_t random(int32_t from, int32_t to)
{ {
return from + ( rand() % (to-from) ); return from + ( Int32Rand() % (to-from) );
} }
static RwObject* GetCurrentAtomicObjectCB(RwObject* pObject, void* data) static RwObject* GetCurrentAtomicObjectCB(RwObject* pObject, void* data)