Tweak to use local random, don't trust mysql's; new seed
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 3 Jun 2003 21:27:06 +0000 (21:27 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 3 Jun 2003 21:27:06 +0000 (21:27 +0000)
includes/Article.php
includes/GlobalFunctions.php
includes/SpecialRandompage.php

index 996ef23..1ca8cf5 100644 (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();
index 1b99cee..394a227 100644 (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;
        }
 }
index b3110f6..344000a 100644 (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?!