From 9df6e29846ad8d7d69069400bd3419fa4749deb6 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 11 Mar 2014 16:43:06 +0100 Subject: ambigator: Add --really-random --- src/ambigator.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/ambigator.c') diff --git a/src/ambigator.c b/src/ambigator.c index 86d6d71c..bf9db16a 100644 --- a/src/ambigator.c +++ b/src/ambigator.c @@ -73,6 +73,7 @@ static void show_help(const char *s) " --fg-graph= Save f and g correlation values to file .\n" " --ncorr= Use correlations per crystal. Default 1000\n" " -j Use threads for CC calculation.\n" +" --really-random Be non-deterministic.\n" ); } @@ -721,6 +722,7 @@ int main(int argc, char *argv[]) int ncorr_set = 0; float mean_nac; int n_threads = 1; + int config_random = 0; /* Long options */ const struct option longopts[] = { @@ -735,6 +737,8 @@ int main(int argc, char *argv[]) {"fg-graph", 1, NULL, 5}, {"ncorr", 1, NULL, 6}, + {"really-random", 0, &config_random, 1}, + {0, 0, NULL, 0} }; @@ -943,6 +947,24 @@ int main(int argc, char *argv[]) } rng = gsl_rng_alloc(gsl_rng_mt19937); + + if ( config_random ) { + + FILE *fh; + unsigned long int seed; + + fh = fopen("/dev/urandom", "r"); + if ( fh == NULL ) { + ERROR("Failed to open /dev/urandom. Try again without" + " --really-random.\n"); + return 1; + } + + fread(&seed, sizeof(seed), 1, fh); + gsl_rng_set(rng, seed); + fclose(fh); + } + for ( i=0; i 0.5); orig_assignments[i] = assignments[i]; -- cgit v1.2.3