From 75f0c94a597dfdb4a767810dbea70fcde9d5a019 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Wed, 5 Jul 2017 21:58:03 +0200 Subject: [PATCH] Add seed example. --- example/ex-multi03.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/example/ex-multi03.c b/example/ex-multi03.c index 21d0e301..1c06a36d 100644 --- a/example/ex-multi03.c +++ b/example/ex-multi03.c @@ -1,5 +1,11 @@ +#include #include +/* Register a dynamic seed to M*LIB. + Shall be done before any M*LIB header inclusion. */ +unsigned long long rand_seed; +#define M_HASH_SEED rand_seed + #include "m-array.h" #include "m-dict.h" #include "m-string.h" @@ -179,9 +185,14 @@ static json_t generate(void) int main(void) { + /* Compute a new random seed for the hash computation */ + srand(time(NULL)); + rand_seed = ((rand() * RAND_MAX + rand()) * RAND_MAX + rand()) * RAND_MAX + rand(); + + /* Generate data */ json_t p = generate(); json_out_str(stdout, p); - /* Output: + /* Typical Output: @dict@{"filter":@real@2.300000@,"tab":@array@[@real@2.000000@,@real@3.000000@]@,"channel":@boolean@TRUE@}@ */ printf("\n");