factor out rndget() code, for adding users
XXX in the future, the entire scheme must be rethinked when we need more XXX entropy for the hash tables; possibly a cheap add using NZAT and re- XXX initialise the LCG only on access and when added (so keep NZAT state XXX separate from LCG state); also, then we will need a more elaborate XXX scheme, such as adding from environment, editor keypresses and timing
This commit is contained in:
parent
b497da1eb4
commit
70e6988d25
3
sh.h
3
sh.h
@ -152,7 +152,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef EXTERN
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.547 2012/04/14 14:07:47 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.548 2012/04/14 14:35:12 tg Exp $");
|
||||
#endif
|
||||
#define MKSH_VERSION "R40 2012/04/07"
|
||||
|
||||
@ -1888,6 +1888,7 @@ size_t array_ref_len(const char *);
|
||||
char *arrayname(const char *);
|
||||
mksh_uari_t set_array(const char *, bool, const char **);
|
||||
uint32_t hash(const void *);
|
||||
mksh_ari_t rndget(void);
|
||||
void rndset(long);
|
||||
|
||||
enum Test_op {
|
||||
|
18
var.c
18
var.c
@ -27,7 +27,7 @@
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.145 2012/04/07 11:19:53 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.146 2012/04/14 14:35:13 tg Exp $");
|
||||
|
||||
/*-
|
||||
* Variables
|
||||
@ -1094,11 +1094,7 @@ getspec(struct tbl *vp)
|
||||
return;
|
||||
break;
|
||||
case V_RANDOM:
|
||||
/*
|
||||
* this is the same Linear Congruential PRNG as Borland
|
||||
* C/C++ allegedly uses in its built-in rand() function
|
||||
*/
|
||||
i = ((lcg_state = 22695477 * lcg_state + 1) >> 16) & 0x7FFF;
|
||||
i = rndget();
|
||||
break;
|
||||
case V_HISTSIZE:
|
||||
i = histsize;
|
||||
@ -1479,6 +1475,16 @@ hash(const void *s)
|
||||
return (h);
|
||||
}
|
||||
|
||||
mksh_ari_t
|
||||
rndget(void)
|
||||
{
|
||||
/*
|
||||
* this is the same Linear Congruential PRNG as Borland
|
||||
* C/C++ allegedly uses in its built-in rand() function
|
||||
*/
|
||||
return (((lcg_state = 22695477 * lcg_state + 1) >> 16) & 0x7FFF);
|
||||
}
|
||||
|
||||
void
|
||||
rndset(long v)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user