diff options
author | Alexandre Jesus <adbjesus@gmail.com> | 2016-09-16 09:25:34 +0100 |
---|---|---|
committer | Alexandre Jesus <adbjesus@gmail.com> | 2016-09-16 09:25:34 +0100 |
commit | d3878228d84dd2296cd85d914f27087d3cae2835 (patch) | |
tree | 8ed40e3d77fe3cb906baf1414da46c0a168226aa /src/common.c | |
parent | 37f41a284d633babeb152dbc0bf0248058fc25c9 (diff) | |
download | libuknapsack-d3878228d84dd2296cd85d914f27087d3cae2835.tar.gz libuknapsack-d3878228d84dd2296cd85d914f27087d3cae2835.zip |
Add pseudo-random shuffler
Diffstat (limited to 'src/common.c')
-rw-r--r-- | src/common.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/common.c b/src/common.c index 7d9e01d..ee98bba 100644 --- a/src/common.c +++ b/src/common.c @@ -5,6 +5,8 @@ #include "structs.h" #include "common.h" +#define RAND_MAX 1 + struct data * input(char fp[]){ int i,j; FILE *f; @@ -36,6 +38,15 @@ int cmp_items_ratio(const void * a, const void * b){ return -1; } +int cmp_items_random(const void *a, const void *b) { + struct item c = *(struct item *)a; + struct item d = *(struct item *)b; + if(rand() > 0.5){ + return 1; + } + return -1; +} + void print_data(struct data * d){ int i; printf("### PRINTING DATA - BEGINNING ###\n"); |