]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/tool/tool.c
Add support for arc4random
[ngircd-alex.git] / src / tool / tool.c
index 1bb3ebe698b0a6f106e09f5d1b85fea51e9f654b..3b9cc255aed18141c38d6548804798bf396ff125 100644 (file)
@@ -144,11 +144,16 @@ ngt_RandomStr(char *String, const size_t len)
        assert(String != NULL);
 
        gettimeofday(&t, NULL);
+#ifndef HAVE_ARC4RANDOM
        srand((unsigned)(t.tv_usec * t.tv_sec));
 
        for (i = 0; i < len; ++i) {
                String[i] = chars[rand() % (sizeof(chars) - 1)];
        }
+#else
+       for (i = 0; i < len; ++i)
+               String[i] = chars[arc4random() % (sizeof(chars) - 1)];
+#endif
        String[len] = '\0';
 
        return String;