- cast to unsigned int for all calls to srand

This commit is contained in:
Mark Vejvoda
2012-10-30 17:12:04 +00:00
parent 69b5f9b39c
commit 5c15a0e9f4
8 changed files with 14 additions and 21 deletions

View File

@@ -346,7 +346,7 @@ void Ai::update() {
//int allowJoinTeam = random.randRange(0, 100);
//srand(time(NULL) + aiInterface->getMyFaction()->getIndex());
Chrono seed(true);
srand(seed.getCurTicks() + aiInterface->getMyFaction()->getIndex());
srand((unsigned int)seed.getCurTicks() + aiInterface->getMyFaction()->getIndex());
int allowJoinTeam = rand() % 100;

View File

@@ -236,20 +236,20 @@ Intro::Intro(Program *program):
//unsigned int seed = time(NULL);
Chrono seed(true);
srand(seed.getCurTicks());
srand((unsigned int)seed.getCurTicks());
int failedLookups=0;
std::map<int,bool> usedIndex;
for(;modelList.size() < models.size();) {
int index = rand() % models.size();
if(usedIndex.find(index) != usedIndex.end()) {
failedLookups++;
srand(seed.getCurTicks() / failedLookups);
srand((unsigned int)seed.getCurTicks() / failedLookups);
continue;
}
//printf("picIndex = %d list count = %d\n",picIndex,coreData.getMiscTextureList().size());
modelList.push_back(models[index]);
usedIndex[index]=true;
srand(seed.getCurTicks() / modelList.size());
srand((unsigned int)seed.getCurTicks() / modelList.size());
}
models = modelList;
}
@@ -426,14 +426,14 @@ Intro::Intro(Program *program):
if(showIntroPicsRandom == true) {
//unsigned int seed = time(NULL);
Chrono seed(true);
srand(seed.getCurTicks());
srand((unsigned int)seed.getCurTicks());
int failedLookups=0;
std::map<int,bool> usedIndex;
for(;intoTexList.size() < showIntroPics;) {
int picIndex = rand() % coreData.getMiscTextureList().size();
if(usedIndex.find(picIndex) != usedIndex.end()) {
failedLookups++;
srand(seed.getCurTicks() / failedLookups);
srand((unsigned int)seed.getCurTicks() / failedLookups);
if(failedLookups > 10000) {
for(unsigned int i = 0;
@@ -451,7 +451,7 @@ Intro::Intro(Program *program):
//printf("picIndex = %d list count = %d\n",picIndex,coreData.getMiscTextureList().size());
intoTexList.push_back(coreData.getMiscTextureList()[picIndex]);
usedIndex[picIndex]=true;
srand(seed.getCurTicks() / intoTexList.size());
srand((unsigned int)seed.getCurTicks() / intoTexList.size());
}
}
else {

View File

@@ -253,9 +253,8 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
listBoxTileset.init(xoffset+460, mapPos, 150);
//listBoxTileset.setItems(results);
setupTilesetList("");
//srand((unsigned int)time(NULL));
Chrono seed(true);
srand(seed.getCurTicks());
srand((unsigned int)seed.getCurTicks());
listBoxTileset.setSelectedItemIndex(rand() % listBoxTileset.getItemCount());
@@ -1568,9 +1567,8 @@ void MenuStateCustomGame::PlayNow(bool saveGame) {
// Max 1000 tries to get a random, unused faction
for(int findRandomFaction = 1; findRandomFaction < 1000; ++findRandomFaction) {
//srand((unsigned int)time(NULL) + findRandomFaction);
Chrono seed(true);
srand(seed.getCurTicks() + findRandomFaction);
srand((unsigned int)seed.getCurTicks() + findRandomFaction);
int selectedFactionIndex = rand() % listBoxFactions[i].getItemCount();
string selectedFactionName = listBoxFactions[i].getItem(selectedFactionIndex);

View File

@@ -250,9 +250,8 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen
GraphicComponent::applyAllCustomProperties(containerName);
char szIRCNick[80]="";
//srand(time(NULL));
Chrono seed(true);
srand(seed.getCurTicks());
srand((unsigned int)seed.getCurTicks());
int randomNickId = rand() % 999;
string netPlayerName=Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str());

View File

@@ -453,9 +453,8 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
if(this->isConnected() == true) {
//RandomGen random;
//sessionKey = random.randRange(-100000, 100000);
//srand((unsigned int)time(NULL) / (this->playerIndex + 1));
Chrono seed(true);
srand(seed.getCurTicks() / (this->playerIndex + 1));
srand((unsigned int)seed.getCurTicks() / (this->playerIndex + 1));
sessionKey = rand() % 1000000;

View File

@@ -536,9 +536,8 @@ Model *SkillType::getAnimation(float animProgress, const Unit *unit,
if(foundSpecificAnimation == false) {
//int modelIndex = random.randRange(0,animations.size()-1);
//srand(time(NULL) + unit->getId());
Chrono seed(true);
srand(seed.getCurTicks() + unit->getId());
srand((unsigned int)seed.getCurTicks() + unit->getId());
modelIndex = rand() % animations.size();
@@ -546,9 +545,8 @@ Model *SkillType::getAnimation(float animProgress, const Unit *unit,
//printf("SELECTING RANDOM Model index = %d [%s] model attributes [%d to %d] for unit [%s - %d] with HP = %d\n",modelIndex,animations[modelIndex]->getFileName().c_str(),attributes.fromHp,attributes.toHp,unit->getType()->getName().c_str(),unit->getId(),unit->getHp());
}
else {
//srand(time(NULL) + unit->getId());
Chrono seed(true);
srand(seed.getCurTicks() + unit->getId());
srand((unsigned int)seed.getCurTicks() + unit->getId());
int filteredModelIndex = rand() % filteredAnimations.size();
modelIndex = filteredAnimations[filteredModelIndex];

View File

@@ -734,7 +734,7 @@ void writeCachedFileCRCValue(string crcCacheFile, uint32 &crcValue) {
if(fp != NULL) {
//RandomGen random;
//int offset = random.randRange(5, 15);
srand((unsigned long)time(NULL) + (unsigned long)crcCacheFile.length());
srand((unsigned int)time(NULL) + (unsigned long)crcCacheFile.length());
int offset = rand() % 15;
if(offset == 0) {
offset = 3;

View File

@@ -440,7 +440,6 @@ const string Properties::getRandomKey(const bool realrandom) const{
int max=getPropertyCount();
int randomIndex=-1;
if(realrandom == true){
//srand((unsigned int)time(NULL));
Chrono seed(true);
srand((unsigned int)seed.getCurTicks());