1
0
mirror of https://github.com/blupi-games/planetblupi synced 2024-12-30 10:15:36 +01:00

Use the Microsoft implementation of rand

It's very important, otherwise the behaviour is changed between the
platforms and the demos are not running correctly.
This commit is contained in:
Mathieu Schroeter 2017-02-19 11:14:00 +01:00
parent afb93060f1
commit c8ca6b918f

View File

@ -49,25 +49,35 @@ POINT ConvLongToPos (LPARAM lParam)
return pos; return pos;
} }
static int g_seed;
// R�initialise le g�n�rateur al�atoire. /* Initialize the Microsoft pseudo-random generator */
void InitRandom() void InitRandom()
{ {
srand (1); g_seed = 1;
// srand (1);
} }
// Retourne un nombre al�atoire compris entre /* We are not using rand from stdlib because on Linux the pseudo-generator
// deux bornes (inclues). * is using an other algorithm. Then the behaviour is not the same on all
* platforms.
* See http://stackoverflow.com/a/1280765/842097
*/
int ms_rand ()
{
g_seed = g_seed * 0x343fd + 0x269EC3;
return (g_seed >> 0x10) & 0x7FFF;
}
/* Returns a random number between two values (included). */
Sint32 Random (Sint32 min, Sint32 max) Sint32 Random (Sint32 min, Sint32 max)
{ {
Sint32 n; Sint32 n;
n = rand(); n = ms_rand (); // replace rand ();
n = min + (n % (max - min + 1)); n = min + (n % (max - min + 1));
return (Sint32)n; return (Sint32) n;
} }
std::string GetLocale () std::string GetLocale ()