From 94f95655c131580953e8c3ed9dd70751c6e8e53f Mon Sep 17 00:00:00 2001 From: tTh Date: Thu, 6 Dec 2018 21:06:34 +0100 Subject: [PATCH] add gaussian fake random value --- fake-values.c | 8 +++++--- funcs.c | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/fake-values.c b/fake-values.c index d1b6a8c..8572d7d 100644 --- a/fake-values.c +++ b/fake-values.c @@ -14,12 +14,14 @@ int verbosity; int main(int argc, char *argv[]) { -int opt; +int opt; +int type = 0; -while ((opt = getopt(argc, argv, "vs")) != -1) { +while ((opt = getopt(argc, argv, "vst:")) != -1) { switch (opt) { case 'v': verbosity++; break; case 's': srand(getpid()); break; + case 't': type = atoi(optarg); break; default: break; } } @@ -29,7 +31,7 @@ if (verbosity > 1) { } -printf("%f %d\n", dtime(), random1000(0)); +printf("%f %d\n", dtime(), random1000(type)); return 0; } diff --git a/funcs.c b/funcs.c index 614f381..9270f5c 100644 --- a/funcs.c +++ b/funcs.c @@ -12,12 +12,24 @@ extern int verbosity; /* --------------------------------------------------------------- */ -int random1000(int foo) +int random1000(int type) { int value; if (verbosity) - fprintf(stderr, ">>> %s(%d)\n", __func__, foo); -value = rand() % 1000; + fprintf(stderr, ">>> %s(%d)\n", __func__, type); + +switch (type) { + case 0: + value = rand() % 1000; + break; + case 1: + value = (rand()%1000 + rand()%1000) / 2; + break; + default: + value = -1; + break; + } + return value; }