From: Amos Jeffries Date: Sun, 8 Feb 2015 16:24:31 +0000 (-0800) Subject: Convert random() in hash test to C++11 random engine X-Git-Tag: merge-candidate-3-v1~109^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a0a4ad8a1535dc40bb6d2ced3d721c47e5995e9;p=thirdparty%2Fsquid.git Convert random() in hash test to C++11 random engine --- diff --git a/lib/hash.cc b/lib/hash.cc index 92b0d8fbc6..7a6c68e48d 100644 --- a/lib/hash.cc +++ b/lib/hash.cc @@ -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); }