ex-1/main.c: make sample size configurable
This commit is contained in:
parent
15eb3dbb88
commit
75bc5caede
15
ex-1/main.c
15
ex-1/main.c
@ -1,5 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <gsl/gsl_randist.h>
|
||||
#include <gsl/gsl_statistics_double.h>
|
||||
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user