Skip to content

Commit

Permalink
Worked with Samy Kamkar to improve LCG entropy.
Browse files Browse the repository at this point in the history
  • Loading branch information
rlerdorf committed Jan 8, 2010
1 parent 1cc974f commit 00c5ca7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ext/standard/lcg.c
Expand Up @@ -78,7 +78,7 @@ static void lcg_seed(TSRMLS_D) /* {{{ */
struct timeval tv;

if (gettimeofday(&tv, NULL) == 0) {
LCG(s1) = tv.tv_sec ^ (~tv.tv_usec);
LCG(s1) = tv.tv_sec ^ (tv.tv_usec<<11);
} else {
LCG(s1) = 1;
}
Expand All @@ -88,6 +88,11 @@ static void lcg_seed(TSRMLS_D) /* {{{ */
LCG(s2) = (long) getpid();
#endif

/* Add entropy to s2 by calling gettimeofday() again */
if (gettimeofday(&tv, NULL) == 0) {
LCG(s2) ^= (tv.tv_usec<<11);
}

LCG(seeded) = 1;
}
/* }}} */
Expand Down

0 comments on commit 00c5ca7

Please sign in to comment.