diff --git a/Makefile b/Makefile index da8dd7a9..543c41a2 100644 --- a/Makefile +++ b/Makefile @@ -115,6 +115,7 @@ SOURCES = \ src/Organya \ src/PixTone \ src/Profile \ + src/Random \ src/Resource \ src/SelStage \ src/Shoot \ diff --git a/src/Game.cpp b/src/Game.cpp index a9231fdc..38c129b5 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -37,6 +37,7 @@ #include "NpcHit.h" #include "NpcTbl.h" #include "Profile.h" +#include "Random.h" #include "SelStage.h" #include "Shoot.h" #include "Sound.h" @@ -54,7 +55,7 @@ BOOL bContinue; int Random(int min, int max) { const int range = max - min + 1; - return min + rand() % range; + return min + msvc_rand() % range; } void PutNumber4(int x, int y, int value, BOOL bZero) diff --git a/src/PixTone.cpp b/src/PixTone.cpp index 07e6fba3..e0c8c547 100644 --- a/src/PixTone.cpp +++ b/src/PixTone.cpp @@ -6,6 +6,8 @@ #include "WindowsWrapper.h" +#include "Random.h" + static signed char gWaveModelTable[6][256]; void MakeWaveTables(void) @@ -54,9 +56,9 @@ void MakeWaveTables(void) gWaveModelTable[4][i] = -0x40; // White noise wave - srand(0); + msvc_srand(0); for (i = 0; i < 256; ++i) - gWaveModelTable[5][i] = (signed char)(rand() & 0xFF) / 2; + gWaveModelTable[5][i] = (signed char)(msvc_rand() & 0xFF) / 2; } BOOL MakePixelWaveData(const PIXTONEPARAMETER *ptp, unsigned char *pData) diff --git a/src/Random.cpp b/src/Random.cpp new file mode 100644 index 00000000..3c324ad3 --- /dev/null +++ b/src/Random.cpp @@ -0,0 +1,15 @@ +#include "Random.h" + +// A replication of MSVC's rand algorithm +static unsigned long next = 1; + +int msvc_rand(void) +{ + next = ((next) * 214013 + 2531011); + return ((next) >> 16) & 0x7FFF; +} + +void msvc_srand(unsigned int seed) +{ + next = seed; +} diff --git a/src/Random.h b/src/Random.h new file mode 100644 index 00000000..253869e3 --- /dev/null +++ b/src/Random.h @@ -0,0 +1,4 @@ +#pragma once + +int msvc_rand(void); +void msvc_srand(unsigned int seed);