aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Sadie Powell2023-07-15 12:56:38 +0100
committerGravatar Sadie Powell2023-07-15 12:56:38 +0100
commitccb7b056d604348f072e77d9b134a3f47e983fcb (patch)
treec9b46064fea0baaad86e13f4ee1597ed4e24a10d /src
parentRename several Windows files to use the same naming scheme. (diff)
Replace rand/rand_s/random with the C++11 random number generator.
Diffstat (limited to 'src')
-rw-r--r--src/helperfuncs.cpp22
-rw-r--r--src/inspircd.cpp10
2 files changed, 6 insertions, 26 deletions
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index 203c5de04..f3a994007 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -28,10 +28,7 @@
*/
-#ifdef _WIN32
-#define _CRT_RAND_S
-#include <stdlib.h>
-#endif
+#include <random>
#include "inspircd.h"
#include "timeutils.h"
@@ -464,17 +461,10 @@ void InspIRCd::DefaultGenRandom(char* output, size_t max)
#if defined HAS_ARC4RANDOM_BUF
arc4random_buf(output, max);
#else
- for (unsigned int i = 0; i < max; ++i)
-# ifdef _WIN32
- {
- unsigned int uTemp;
- if(rand_s(&uTemp) != 0)
- output[i] = rand();
- else
- output[i] = uTemp;
- }
-# else
- output[i] = random();
-# endif
+ static std::random_device device;
+ static std::mt19937 engine(device());
+ static std::uniform_int_distribution<char> dist;
+ for (size_t i = 0; i < max; ++i)
+ output[i] = dist(engine);
#endif
}
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index a4c6c9edc..c6aab7dac 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -341,15 +341,6 @@ namespace
ServerInstance->Config->CommandLine.writelog = !do_nolog;
ServerInstance->Config->CommandLine.writepid = !do_nopid;
}
- // Seeds the random number generator if applicable.
- void SeedRng(timespec ts)
- {
-#if defined _WIN32
- srand(ts.tv_nsec ^ ts.tv_sec);
-#elif !defined HAS_ARC4RANDOM_BUF
- srandom(static_cast<int>(ts.tv_nsec ^ ts.tv_sec));
-#endif
- }
// Sets handlers for various process signals.
void SetSignals()
@@ -468,7 +459,6 @@ InspIRCd::InspIRCd(int argc, char** argv)
this->startup_time = TIME.tv_sec;
IncreaseCoreDumpSize();
- SeedRng(TIME);
SocketEngine::Init();
this->Config = new ServerConfig;