]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/helperfuncs.cpp
Use arc4random_buf() instead of random() when available.
[user/henk/code/inspircd.git] / src / helperfuncs.cpp
index 8ced78ae8ac720d880f14d34cdba42da5144ddc7..6830612c70bedbc1bf0ee473aef6673d7d18d84e 100644 (file)
@@ -477,8 +477,11 @@ unsigned long InspIRCd::GenRandomInt(unsigned long max)
 // This is overridden by a higher-quality algorithm when SSL support is loaded
 void InspIRCd::DefaultGenRandom(char* output, size_t max)
 {
-       for(unsigned int i=0; i < max; i++)
-#ifdef _WIN32
+#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)
@@ -486,7 +489,8 @@ void InspIRCd::DefaultGenRandom(char* output, size_t max)
                else
                        output[i] = uTemp;
        }
-#else
+# else
                output[i] = random();
+# endif
 #endif
 }