From ada2511a52067ff1fd006993831279faba79241f Mon Sep 17 00:00:00 2001 From: Alexandre Jesus Date: Wed, 2 Nov 2016 21:31:27 +0000 Subject: Use sys/time.h to seed random generator --- src/main/uknapsack.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/uknapsack.c b/src/main/uknapsack.c index e7f3055..1c66430 100644 --- a/src/main/uknapsack.c +++ b/src/main/uknapsack.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "common.h" #include "structs.h" #include "dfs.h" @@ -20,8 +21,12 @@ int main(int argc, char * argv[]){ data = input(argv[3]); + /* Seed Random Generator */ + struct timeval tv; + gettimeofday(&tv,NULL); + srand(tv.tv_sec + tv.tv_usec); + /* Sort data */ - srand(time(NULL)); if(strcmp(argv[2], "random") == 0) { qsort(data->items, data->N, sizeof(struct item), cmp_items_random); } else if(strcmp(argv[2], "ratio") == 0) { -- cgit v1.2.3