Tweak to use local random, don't trust mysql's; new seed

This commit is contained in:
Brion Vibber 2003-06-03 21:27:06 +00:00
parent efca89ebbe
commit 5648184915
3 changed files with 7 additions and 5 deletions

View file

@ -591,6 +591,8 @@ name=\"wpSummary\" maxlength=200 size=60><br>
$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><br>
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();

View file

@ -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;
}
}

View file

@ -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?!