Skip to content

Commit c35bb69

Browse files
authored
rand() swapped with std::mt19937 (#112)
1 parent 6381882 commit c35bb69

4 files changed

Lines changed: 15 additions & 3 deletions

File tree

KBotExt/Definitions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <vector>
44
#include <string>
55

6-
#define RandomInt(min, max) (rand() % (max - min + 1) + min)
6+
//#define RandomInt(min, max) (rand() % (max - min + 1) + min)
77

88
struct ChampMinimal
99
{

KBotExt/KBotExt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ int WINAPI wWinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPWSTR
7979
#endif
8080

8181
//Randomize using current time, todo swap with recent c++ random
82-
srand(static_cast<unsigned>(time(0)));
82+
//srand(static_cast<unsigned>(time(0)));
8383

8484
Config::Load();
85-
std::wstring sClassName = Utils::RandomWString(RandomInt(5, 10), { 0x2e80, 0xfffff });
85+
std::wstring sClassName = Utils::RandomWString(Utils::RandomInt(5, 10), { 0x2e80, 0xfffff });
8686
LPCWSTR lpszOverlayClassName = sClassName.c_str();
8787
//Register window class information
8888
WNDCLASSEXW wc = { sizeof(WNDCLASSEXW), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, sClassName.c_str(), NULL };

KBotExt/Utils.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@
44
#include <filesystem>
55
#include <array>
66
#include <cwctype>
7+
#include <random>
78
//URLDownloadToFileA
89
#include <urlmon.h>
910
#pragma comment(lib, "urlmon.lib")
1011

1112
#include "Utils.h"
1213
#include "Definitions.h"
1314

15+
int Utils::RandomInt(int min, int max)
16+
{
17+
std::random_device rd;
18+
std::mt19937 gen(rd());
19+
std::uniform_int_distribution<> distr(min, max);
20+
21+
return distr(gen);
22+
}
23+
1424
std::string Utils::ToLower(std::string str)
1525
{
1626
std::transform(str.begin(), str.end(), str.begin(),

KBotExt/Utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ class Utils
77
Utils() = default;
88
~Utils() = default;
99

10+
static int RandomInt(int min, int max);
11+
1012
static std::string ToLower(std::string str);
1113
static std::wstring ToLower(std::wstring wstr);
1214

0 commit comments

Comments
 (0)