Improve the initial seeding of the randm() RNG. This is the RNG selected
for $rand() when RANDOM_SOURCE is 1. git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@359 13b04d17-f746-0410-82c6-800466cd88b0
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
[Changes 1.2c01]
|
||||
|
||||
* Improve the initial seeding of the randm() fallback RNG. (caf)
|
||||
|
||||
* Strengthen the cookie generation algorithm for /detach. (caf)
|
||||
|
||||
* RANDOM_SOURCE now only affects the rand() scripting function. (caf)
|
||||
|
||||
@@ -3139,15 +3139,22 @@ static const long RAND_A = 16807L;
|
||||
static const long RAND_M = 2147483647L;
|
||||
static const long RAND_Q = 127773L;
|
||||
static const int RAND_R = 2836L;
|
||||
static u_long z = 0;
|
||||
long t;
|
||||
static unsigned long z = 0;
|
||||
|
||||
if (z == 0)
|
||||
z = (u_long) getuid();
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
get_time(&tv);
|
||||
z = tv.tv_usec << 12;
|
||||
z ^= (unsigned long)tv.tv_sec;
|
||||
z ^= (unsigned long)getuid() << 16;
|
||||
z ^= (unsigned long)getpid();
|
||||
}
|
||||
|
||||
if (l == 0)
|
||||
{
|
||||
t = RAND_A * (z % RAND_Q) - RAND_R * (z / RAND_Q);
|
||||
long t = RAND_A * (z % RAND_Q) - RAND_R * (z / RAND_Q);
|
||||
if (t > 0)
|
||||
z = t;
|
||||
else
|
||||
@@ -3156,9 +3163,6 @@ static u_long z = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (l < 0)
|
||||
z = (u_long) getuid();
|
||||
else
|
||||
z = l;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user