Skip to content

Commit

Permalink
boxart: image mix up due to broken rand() on windows
Browse files Browse the repository at this point in the history
srand() wasn't called and rand() returns the same number twice on
windows (RAND_MAX is only 32767).
Use c++11 random instead.
Issue #1231
  • Loading branch information
flyinghead committed Oct 10, 2023
1 parent 0e12153 commit 417a42a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/rend/boxart/scraper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "reios/reios.h"
#include "pvrparser.h"
#include <stb_image_write.h>
#include <random>

bool Scraper::downloadImage(const std::string& url, const std::string& localName)
{
Expand Down Expand Up @@ -60,10 +61,14 @@ bool Scraper::downloadImage(const std::string& url, const std::string& localName

std::string Scraper::makeUniqueFilename(const std::string& url)
{
static std::random_device randomDev;
static std::mt19937 mt(randomDev());
static std::uniform_int_distribution<int> dist(1, 1000000000);

std::string extension = get_file_extension(url);
std::string path;
do {
path = saveDirectory + std::to_string(rand()) + "." + extension;
path = saveDirectory + std::to_string(dist(mt)) + "." + extension;
} while (file_exists(path));
return path;
}
Expand Down

0 comments on commit 417a42a

Please sign in to comment.