From cffabce8ab204bda6d51bdee0c0b669653687987 Mon Sep 17 00:00:00 2001 From: Silent Date: Thu, 9 Mar 2017 00:53:03 +0100 Subject: [PATCH] fix rand() misuse --- SilentPatchSA/SilentPatchSA.cpp | 6 +++--- SilentPatchSA/StdAfxSA.h | 1 + SilentPatchSA/VehicleSA.cpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 2e5b8cd..fff6252 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -786,10 +786,10 @@ int NewFrameRender(int nEvent, void* pParam) #include #include -int Int32Rand() +static std::ranlux48 generator (time(nullptr)); +int32_t Int32Rand() { - static std::ranlux48 generator (time(nullptr)); - return generator() & 0x7FFFFFFF; + return generator() & INT32_MAX; } void (*FlushSpriteBuffer)() = AddressByVersion(0x70CF20, 0x70D750, 0x7591E0, 0x753AE0, 0x753A00); diff --git a/SilentPatchSA/StdAfxSA.h b/SilentPatchSA/StdAfxSA.h index 6d9f483..026f2a6 100644 --- a/SilentPatchSA/StdAfxSA.h +++ b/SilentPatchSA/StdAfxSA.h @@ -30,6 +30,7 @@ extern void (*GTAdelete)(void* data); extern const char* (*GetFrameNodeName)(RwFrame*); extern RpHAnimHierarchy* (*GetAnimHierarchyFromSkinClump)(RpClump*); +int32_t Int32Rand(); extern unsigned char& nGameClockDays; extern unsigned char& nGameClockMonths; diff --git a/SilentPatchSA/VehicleSA.cpp b/SilentPatchSA/VehicleSA.cpp index f4b2af6..010dd25 100644 --- a/SilentPatchSA/VehicleSA.cpp +++ b/SilentPatchSA/VehicleSA.cpp @@ -19,7 +19,7 @@ WRAPPER bool CVehicle::IsLawEnforcementVehicle() { VARJMP(varIsLawEnforcementVeh 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)