]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Convert random() in hash test to C++11 random engine
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 8 Feb 2015 16:24:31 +0000 (08:24 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 8 Feb 2015 16:24:31 +0000 (08:24 -0800)
lib/hash.cc

index 92b0d8fbc61f5d6dbb9c43bee1e28baa336bc174..7a6c68e48d22513d73d4dd001b3aa268ded863bf 100644 (file)
@@ -343,12 +343,15 @@ main(void)
     }
     printf("done creating hash table: %d\n", hid);
 
+    std::mt19937 mt;
+    std::uniform_int_distribution<> dist(0,16);
+
     while (fgets(buf, BUFSIZ, stdin)) {
         buf[strlen(buf) - 1] = '\0';
         printf("Inserting '%s' for item %p to hash table: %d\n",
                buf, buf, hid);
         hash_insert(hid, xstrdup(buf), (void *) 0x12345678);
-        if (random() % 17 == 0)
+        if (dist(mt) == 0)
             strcpy(todelete, buf);
     }