From 5648184915d6da23a8cd213e6a8d98f906cd01b0 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 3 Jun 2003 21:27:06 +0000 Subject: [PATCH] Tweak to use local random, don't trust mysql's; new seed --- includes/Article.php | 4 +++- includes/GlobalFunctions.php | 3 ++- includes/SpecialRandompage.php | 5 ++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 996ef23ea5..1ca8cf5f94 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -591,6 +591,8 @@ name=\"wpSummary\" maxlength=200 size=60>
$now = wfTimestampNow(); $won = wfInvertTimestamp( $now ); + wfSeedRandom(); + $rand = mt_rand() / mt_getrandmax(); $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," . "cur_comment,cur_user,cur_timestamp,cur_minor_edit,cur_counter," . "cur_restrictions,cur_user_text,cur_is_redirect," . @@ -599,7 +601,7 @@ name=\"wpSummary\" maxlength=200 size=60>
wfStrencode( $summary ) . "', '" . $wgUser->getID() . "', '{$now}', " . ( $isminor ? 1 : 0 ) . ", 0, '', '" . - wfStrencode( $wgUser->getName() ) . "', $redir, 1, RAND(), '{$now}', '{$won}')"; + wfStrencode( $wgUser->getName() ) . "', $redir, 1, $rand, '{$now}', '{$won}')"; $res = wfQuery( $sql, $fname ); $newid = wfInsertId(); diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 1b99cee95b..394a227f55 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -32,7 +32,8 @@ function wfSeedRandom() global $wgRandomSeeded; if ( ! $wgRandomSeeded ) { - mt_srand( (double)microtime() * 1000000 ); + $seed = hexdec(substr(md5(microtime()),-8)) & 0x7fffffff; + mt_srand( $seed ); $wgRandomSeeded = true; } } diff --git a/includes/SpecialRandompage.php b/includes/SpecialRandompage.php index b3110f6532..344000a211 100644 --- a/includes/SpecialRandompage.php +++ b/includes/SpecialRandompage.php @@ -6,16 +6,15 @@ function wfSpecialRandompage() $fname = "wfSpecialRandompage"; wfSeedRandom(); + $rand = mt_rand() / mt_getrandmax(); $sqlget = "SELECT cur_id,cur_title FROM cur USE INDEX (cur_random) WHERE cur_namespace=0 AND cur_is_redirect=0 - AND cur_random>RAND() + AND cur_random>$rand ORDER BY cur_random LIMIT 1"; $res = wfQuery( $sqlget, $fname ); if( $s = wfFetchObject( $res ) ) { - $sql = "UPDATE cur SET cur_random=RAND() WHERE cur_id={$s->cur_id}"; - wfQuery( $sql, $fname ); $rt = wfUrlEncode( $s->cur_title ); } else { # No articles?! -- 2.20.1