Add seed example.
This commit is contained in:
1 parent
1dbc71c2a2
commit
75f0c94a59
1 file changed
+12
-1
+12
-1
@@ -1,5 +1,11 @@
|
|||||||
|
#include <time.h>
|
||||||
#include <stdio.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-array.h"
|
||||||
#include "m-dict.h"
|
#include "m-dict.h"
|
||||||
#include "m-string.h"
|
#include "m-string.h"
|
||||||
@@ -179,9 +185,14 @@ static json_t generate(void)
|
|||||||
|
|
||||||
int main(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_t p = generate();
|
||||||
json_out_str(stdout, p);
|
json_out_str(stdout, p);
|
||||||
/* Output:
|
/* Typical Output:
|
||||||
@dict@{"filter":@real@2.300000@,"tab":@array@[@real@2.000000@,@real@3.000000@]@,"channel":@boolean@TRUE@}@
|
@dict@{"filter":@real@2.300000@,"tab":@array@[@real@2.000000@,@real@3.000000@]@,"channel":@boolean@TRUE@}@
|
||||||
*/
|
*/
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|||||||
Reference in new issue
Block a user