aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2014-01-20 13:58:04 +0100
committerThomas White <taw@physics.org>2014-01-20 17:20:14 +0100
commitcffa7bca585c147b28fd8889eae0857f8d3e97fb (patch)
tree308a3a8fe4cb995ebc6d7a6c0611bee55973e138 /src
parent90ee3c269580104f2d16d28aeaa565063f6fc1f2 (diff)
partial_sim: Add --really-random
Diffstat (limited to 'src')
-rw-r--r--src/partial_sim.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/src/partial_sim.c b/src/partial_sim.c
index d9c9ae9f..97e2d14d 100644
--- a/src/partial_sim.c
+++ b/src/partial_sim.c
@@ -371,6 +371,7 @@ int main(int argc, char *argv[])
double full_stddev = 1000.0;
double noise_stddev = 20.0;
gsl_rng *rng_for_seeds;
+ int config_random = 0;
/* Long options */
const struct option longopts[] = {
@@ -389,6 +390,8 @@ int main(int argc, char *argv[])
{"full-stddev", 1, NULL, 4},
{"noise-stddev", 1, NULL, 5},
+ {"really-random", 0, &config_random, 1},
+
{0, 0, NULL, 0}
};
@@ -632,12 +635,38 @@ int main(int argc, char *argv[])
ERROR("Failed to allocate RNGs\n");
return 1;
}
- rng_for_seeds = gsl_rng_alloc(gsl_rng_mt19937);
- for ( i=0; i<n_threads; i++ ) {
- qargs.rngs[i] = gsl_rng_alloc(gsl_rng_mt19937);
- gsl_rng_set(qargs.rngs[i], gsl_rng_get(rng_for_seeds));
+
+ if ( config_random ) {
+
+ FILE *fh;
+
+ fh = fopen("/dev/urandom", "r");
+ if ( fh == NULL ) {
+ ERROR("Failed to open /dev/urandom. Try again without"
+ " --really-random.\n");
+ return 1;
+ }
+
+ for ( i=0; i<n_threads; i++ ) {
+
+ unsigned long int seed;
+
+ fread(&seed, sizeof(seed), 1, fh);
+ qargs.rngs[i] = gsl_rng_alloc(gsl_rng_mt19937);
+ gsl_rng_set(qargs.rngs[i], seed);
+
+ }
+
+ fclose(fh);
+
+ } else {
+ rng_for_seeds = gsl_rng_alloc(gsl_rng_mt19937);
+ for ( i=0; i<n_threads; i++ ) {
+ qargs.rngs[i] = gsl_rng_alloc(gsl_rng_mt19937);
+ gsl_rng_set(qargs.rngs[i], gsl_rng_get(rng_for_seeds));
+ }
+ gsl_rng_free(rng_for_seeds);
}
- gsl_rng_free(rng_for_seeds);
for ( i=0; i<NBINS; i++ ) {
qargs.n_ref[i] = 0;
@@ -702,6 +731,7 @@ int main(int argc, char *argv[])
for ( i=0; i<n_threads; i++ ) {
gsl_rng_free(qargs.rngs[i]);
}
+ free(qargs.rngs);
pthread_rwlock_destroy(&qargs.full_lock);
close_stream(stream);
cell_free(cell);