diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2020-02-03 05:41:11 -0800 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2020-02-03 05:45:49 -0800 |
commit | de64b7014b9dc54fe06b52e14dfc685d72f6ab0b (patch) | |
tree | 6f6460fa1b109628b8266c0338484106eba895ce /src/libs/sig/sig.c | |
parent | fff934678207e71bc873b12916fd3c690b8862cc (diff) |
libs/sig: add sig_ops_rand random generator
(Ab)uses rand_r by feeding ticks_ms as seedp for pseudo-random
numbers deterministically derived from ticks_ms.
Diffstat (limited to 'src/libs/sig/sig.c')
-rw-r--r-- | src/libs/sig/sig.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/libs/sig/sig.c b/src/libs/sig/sig.c index cd179e2..fea83b6 100644 --- a/src/libs/sig/sig.c +++ b/src/libs/sig/sig.c @@ -83,6 +83,12 @@ int main(int argc, char *argv[]) printf("null output=%f\n", sig_output(sig, 0)); sig = sig_free(sig); + sig = sig_new(&sig_ops_rand); + for (unsigned j = 0; j < 2; j++) { + for (unsigned i = 0; i < 10; i++) + printf("rand j=%u i=%u output=%f\n", j, i, sig_output(sig, i)); + } + sig = sig_new(&sig_ops_sin, sig_new(&sig_ops_const, 2.f)); for (unsigned i = 0; i < 1000; i++) printf("sin 2hz output %i=%f\n", i, sig_output(sig, i)); |