Add seed example.

This commit is contained in:
Patrick Pelissier committed 2017-07-05 21:58:03 +02:00
1 parent 1dbc71c2a2
commit 75f0c94a59
1 file changed
+12 -1
+12 -1
View File
@@ -1,5 +1,11 @@
#include <time.h>
#include <stdio.h>
/* 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");