From 75bc5caedea8b5c80fb94b4c2a8f3f041fb1ffaa Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Sat, 25 Apr 2020 22:11:39 +0000 Subject: [PATCH] ex-1/main.c: make sample size configurable --- ex-1/main.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ex-1/main.c b/ex-1/main.c index 293e052..112fd23 100644 --- a/ex-1/main.c +++ b/ex-1/main.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -15,12 +16,24 @@ * distribution. */ int main(int argc, char** argv) { + size_t samples = 50000; + + /* Process CLI arguments */ + for (size_t i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-n")) samples = atol(argv[++i]); + else { + fprintf(stderr, "Usage: %s -[hn]\n", argv[0]); + fprintf(stderr, "\t-h\tShow this message.\n"); + fprintf(stderr, "\t-n N\tThe size of sample to generate. (default: 50000)\n"); + return EXIT_FAILURE; + } + } + // initialize an RNG gsl_rng_env_setup(); gsl_rng *r = gsl_rng_alloc(gsl_rng_default); // prepare histogram - size_t samples = 50000; double* sample = calloc(samples, sizeof(double)); double min = -10; double max = 10;