summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorAlexandre Jesus <adbjesus@gmail.com>2016-11-02 21:31:27 +0000
committerAlexandre Jesus <adbjesus@gmail.com>2016-11-02 21:31:27 +0000
commitada2511a52067ff1fd006993831279faba79241f (patch)
tree8b218abadf3480527ff22d682dd1453b917dc90c /src/main
parent73010dc96357a9715b87421534bebc19ecd5863d (diff)
downloadlibuknapsack-ada2511a52067ff1fd006993831279faba79241f.tar.gz
libuknapsack-ada2511a52067ff1fd006993831279faba79241f.zip
Use sys/time.h to seed random generator
Diffstat (limited to 'src/main')
-rw-r--r--src/main/uknapsack.c7
1 files changed, 6 insertions, 1 deletions
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 <time.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/time.h>
#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) {