Commit 920c69a1 authored by nanahira's avatar nanahira

fix rand

parent 058daeed
Pipeline #28631 failed with stages
in 25 seconds
...@@ -90,8 +90,10 @@ bool Game::Initialize() { ...@@ -90,8 +90,10 @@ bool Game::Initialize() {
size_t count = skins.size(); size_t count = skins.size();
if(count > 0) { if(count > 0) {
int index = -1; int index = -1;
if(gameConf.skin_index < 0) if(gameConf.skin_index < 0) {
index = rand() % count; std::random_device rd;
index = rd() % count;
}
else if((size_t)gameConf.skin_index <= skins.size()) else if((size_t)gameConf.skin_index <= skins.size())
index = skins.size() - gameConf.skin_index; // reverse index index = skins.size() - gameConf.skin_index; // reverse index
if(index >= 0) if(index >= 0)
......
...@@ -71,8 +71,9 @@ irr::video::ITexture* ImageManager::GetRandomImage(int image_type) { ...@@ -71,8 +71,9 @@ irr::video::ITexture* ImageManager::GetRandomImage(int image_type) {
return NULL; return NULL;
char ImageName[1024]; char ImageName[1024];
wchar_t fname[1024]; wchar_t fname[1024];
std::random_device rd;
if(saved_image_id[image_type] == -1) if(saved_image_id[image_type] == -1)
saved_image_id[image_type] = rand() % count; saved_image_id[image_type] = rd() % count;
int image_id = saved_image_id[image_type]; int image_id = saved_image_id[image_type];
auto name = ImageList[image_type][image_id].c_str(); auto name = ImageList[image_type][image_id].c_str();
myswprintf(fname, L"./textures/%ls", name); myswprintf(fname, L"./textures/%ls", name);
...@@ -85,8 +86,9 @@ irr::video::ITexture* ImageManager::GetRandomImage(int image_type, s32 width, s3 ...@@ -85,8 +86,9 @@ irr::video::ITexture* ImageManager::GetRandomImage(int image_type, s32 width, s3
return NULL; return NULL;
char ImageName[1024]; char ImageName[1024];
wchar_t fname[1024]; wchar_t fname[1024];
std::random_device rd;
if(saved_image_id[image_type] == -1) if(saved_image_id[image_type] == -1)
saved_image_id[image_type] = rand() % count; saved_image_id[image_type] = rd() % count;
int image_id = saved_image_id[image_type]; int image_id = saved_image_id[image_type];
auto name = ImageList[image_type][image_id].c_str(); auto name = ImageList[image_type][image_id].c_str();
myswprintf(fname, L"./textures/%ls", name); myswprintf(fname, L"./textures/%ls", name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment