Replace rand() with SafeRandom()

liquid_container
Lukas Werling 2016-04-20 21:20:58 +02:00
parent 1f5dc0aec6
commit febc5f91bd
3 changed files with 9 additions and 6 deletions

View File

@ -28,6 +28,7 @@
#include "landscape/C4Material.h"
#include "landscape/C4Landscape.h"
#include "lib/C4Log.h"
#include "lib/C4Random.h"
#include "lib/StdColors.h"
#include <ctype.h>
@ -570,9 +571,9 @@ void C4TextureMap::StoreMapPalette(CStdPalette *Palette, C4MaterialMap &rMateria
if (j >= i) break;
// change randomly
Palette->Colors[i] = C4RGB(
(rand() < RAND_MAX / 2) ? GetRedValue(Palette->Colors[i]) + 3 : GetRedValue(Palette->Colors[i]) - 3,
(rand() < RAND_MAX / 2) ? GetGreenValue(Palette->Colors[i]) + 3 : GetGreenValue(Palette->Colors[i]) - 3,
(rand() < RAND_MAX / 2) ? GetBlueValue(Palette->Colors[i]) + 3 : GetBlueValue(Palette->Colors[i]) - 3);
SafeRandom(2) ? GetRedValue(Palette->Colors[i]) + 3 : GetRedValue(Palette->Colors[i]) - 3,
SafeRandom(2) ? GetGreenValue(Palette->Colors[i]) + 3 : GetGreenValue(Palette->Colors[i]) - 3,
SafeRandom(2) ? GetBlueValue(Palette->Colors[i]) + 3 : GetBlueValue(Palette->Colors[i]) - 3);
}
}

View File

@ -17,6 +17,7 @@
#include "C4Include.h"
#include "network/C4NetIO.h"
#include "lib/C4Random.h"
#include <iostream>
#include <sstream>
@ -101,7 +102,7 @@ int main(int argc, char * argv[])
for (i = 0; i < sizeof(DummyData); i++)
DummyData[i] = 'A' + i % 100;
srand(time(NULL));
FixedRandom(time(NULL));
#ifdef USE_UDP
C4NetIOUDP NetIO;

View File

@ -15,6 +15,7 @@
*/
#include "C4Include.h"
#include "network/C4NetIO.h"
#include "lib/C4Random.h"
#include "config/C4Constants.h"
#include "config/C4Config.h"
@ -1887,7 +1888,7 @@ bool C4NetIOUDP::InitBroadcast(addr_t *pBroadcastAddr)
{
// create new - random - address
MCAddr.sin_addr.s_addr =
0x000000ef | ((rand() & 0xff) << 24) | ((rand() & 0xff) << 16) | ((rand() & 0xff) << 8);
0x000000ef | (SafeRandom(0x1000000) << 8);
// init broadcast
if (!C4NetIOSimpleUDP::InitBroadcast(&MCAddr))
return false;
@ -3031,7 +3032,7 @@ bool C4NetIOUDP::DoLoopbackTest()
if (!C4NetIOSimpleUDP::getMCLoopback()) return false;
// send test packet
const PacketHdr TestPacket = { uint8_t(IPID_Test | 0x80), static_cast<uint32_t>(rand()) };
const PacketHdr TestPacket = { uint8_t(IPID_Test | 0x80), SafeRandom(UINT32_MAX) };
if (!C4NetIOSimpleUDP::Broadcast(C4NetIOPacket(&TestPacket, sizeof(TestPacket))))
return false;