mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
Improve seed() builtin
This commit is contained in:
11
seed.c
11
seed.c
@@ -80,8 +80,8 @@
|
|||||||
#endif
|
#endif
|
||||||
#if defined(HAVE_STDLIB_H)
|
#if defined(HAVE_STDLIB_H)
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
# define RANDOM_CNT (64) /* double random() call repeat count */
|
# define RANDOM_CNT (8) /* double random() call repeat count */
|
||||||
# define INITSTATE_SIZE (256) /* initstate pool size */
|
# define INITSTATE_SIZE (16) /* initstate pool size */
|
||||||
#endif
|
#endif
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include "alloc.h"
|
#include "alloc.h"
|
||||||
@@ -469,6 +469,7 @@ pseudo_seed(void)
|
|||||||
char *initstate_ret; /* return from initstate() call */
|
char *initstate_ret; /* return from initstate() call */
|
||||||
char initstate_tbl[INITSTATE_SIZE]; /* initstate pool */
|
char initstate_tbl[INITSTATE_SIZE]; /* initstate pool */
|
||||||
long random_after[RANDOM_CNT]; /* random() post initstate() */
|
long random_after[RANDOM_CNT]; /* random() post initstate() */
|
||||||
|
char *setstate_ret; /* return from setstate() call */
|
||||||
int j;
|
int j;
|
||||||
#endif /* HAVE_STDLIB_H */
|
#endif /* HAVE_STDLIB_H */
|
||||||
#if defined(HAVE_ENVIRON)
|
#if defined(HAVE_ENVIRON)
|
||||||
@@ -663,6 +664,9 @@ pseudo_seed(void)
|
|||||||
random_after[j+1] = (random() << 1);
|
random_after[j+1] = (random() << 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* restore previous state */
|
||||||
|
setstate_ret = setstate(initstate_ret);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* hash all the data from random() and friends
|
* hash all the data from random() and friends
|
||||||
*/
|
*/
|
||||||
@@ -681,6 +685,9 @@ pseudo_seed(void)
|
|||||||
hash_val = private_hash64_buf(hash_val,
|
hash_val = private_hash64_buf(hash_val,
|
||||||
(char *)random_after,
|
(char *)random_after,
|
||||||
sizeof(random_after));
|
sizeof(random_after));
|
||||||
|
hash_val = private_hash64_buf(hash_val,
|
||||||
|
(char *)setstate_ret,
|
||||||
|
sizeof(setstate_ret));
|
||||||
#endif /* HAVE_STDLIB_H */
|
#endif /* HAVE_STDLIB_H */
|
||||||
|
|
||||||
#if defined(HAVE_ARC4RANDOM)
|
#if defined(HAVE_ARC4RANDOM)
|
||||||
|
Reference in New Issue
Block a user