From 61bf26278a9904a2e450841ad310a43c6a04a4de Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Sat, 7 Feb 2015 21:39:52 -0800 Subject: [PATCH] Update Splay unit test to use C++11 random --- test-suite/splay.cc | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/test-suite/splay.cc b/test-suite/splay.cc index 4bed13bb0e..10d1996fa1 100644 --- a/test-suite/splay.cc +++ b/test-suite/splay.cc @@ -12,14 +12,14 @@ */ #include "squid.h" +#include "splay.h" +#include "util.h" #include #if HAVE_UNISTD_H #include #endif - -#include "splay.h" -#include "util.h" +#include class intnode { @@ -129,16 +129,17 @@ destintref (intnode &) int main(int argc, char *argv[]) { + std::mt19937 generator; + std::uniform_int_distribution distribution; + auto nextRandom = std::bind (distribution, generator); + { - int i; - intnode *I; /* test void * splay containers */ splayNode *top = NULL; - squid_srandom(time(NULL)); - for (i = 0; i < 100; ++i) { - I = (intnode *)xcalloc(sizeof(intnode), 1); - I->i = squid_random(); + for (int i = 0; i < 100; ++i) { + intnode *I = (intnode *)xcalloc(sizeof(intnode), 1); + I->i = nextRandom(); if (top) top = top->insert(I, compareintvoid); else @@ -161,7 +162,7 @@ main(int argc, char *argv[]) for ( int i = 0; i < 100; ++i) { intnode *I; I = new intnode; - I->i = squid_random(); + I->i = nextRandom(); safeTop = safeTop->insert(I, compareint); } @@ -176,7 +177,7 @@ main(int argc, char *argv[]) for (int i = 0; i < 100; ++i) { intnode I; - I.i = squid_random(); + I.i = nextRandom(); safeTop = safeTop->insert(I, compareintref); } @@ -210,7 +211,7 @@ main(int argc, char *argv[]) for (int i = 0; i < 100; ++i) { intnode I; - I.i = squid_random(); + I.i = nextRandom(); if (I.i > 50 && I.i < 10000000) safeTop->insert(I, compareintref); -- 2.47.2