X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsn-evolution.c;fp=src%2Fsn-evolution.c;h=48012a620b6d0d2b4cacd018dc6e98bbe886457c;hb=6036d137f84b8ee853779ce7d3513f72f9f62621;hp=e319660d676fc5724c50066593020e5dedab79a6;hpb=d11d0ba1cefd4059551eeea3839d5065b5ba4375;p=sort-networks.git diff --git a/src/sn-evolution.c b/src/sn-evolution.c index e319660..48012a6 100644 --- a/src/sn-evolution.c +++ b/src/sn-evolution.c @@ -16,6 +16,7 @@ #include "sn_network.h" #include "sn_population.h" +#include "sn_random.h" /* Yes, this is ugly, but the GNU libc doesn't export it with the above flags. * */ @@ -39,32 +40,6 @@ static void sigint_handler (int signal) do_loop++; } /* void sigint_handler */ -static int init_random (void) -{ - int fd; - unsigned int r; - - fd = open ("/dev/random", O_RDONLY); - if (fd < 0) - { - perror ("open"); - return (-1); - } - - read (fd, (void *) &r, sizeof (r)); - close (fd); - - srand (r); - - return (0); -} /* int init_random */ - -static int bounded_random (int upper_bound) -{ - double r = ((double) rand ()) / ((double) RAND_MAX); - return ((int) (r * upper_bound)); -} - static void exit_usage (const char *name) { printf ("Usage: %s [options]\n" @@ -255,8 +230,8 @@ static int create_offspring (void) int pos; enum sn_network_cut_dir_e dir; - pos = bounded_random (SN_NETWORK_INPUT_NUM (n)); - dir = (bounded_random (2) == 0) ? DIR_MIN : DIR_MAX; + pos = sn_bounded_random (0, SN_NETWORK_INPUT_NUM (n) - 1); + dir = (sn_bounded_random (0, 1) == 0) ? DIR_MIN : DIR_MAX; assert ((pos >= 0) && (pos < SN_NETWORK_INPUT_NUM (n))); @@ -303,8 +278,6 @@ int main (int argc, char **argv) if (initial_input_file == NULL) exit_usage (argv[0]); - init_random (); - memset (&sigint_action, '\0', sizeof (sigint_action)); sigint_action.sa_handler = sigint_handler; sigaction (SIGINT, &sigint_action, NULL);