예제 #1
0
function drShuffle(&$arr)
{
    mt_srand(makeSeed());
    for ($i = 0; $i < sizeof($arr); $i++) {
        $swp = mt_rand(0, sizeof($arr) - 1);
        $tmp = $arr[$swp];
        $arr[$swp] = $arr[$i];
        $arr[$i] = $tmp;
    }
}
예제 #2
0
<?php

include "include/config.php";
include "include/db.php";
function makeSeed()
{
    list($usec, $sec) = explode(' ', microtime());
    return (double) $sec + (double) $usec * 100000;
}
db_connect($host, $username, $password, $database);
// TODO generate a random book and chapter then send a  header(Location) update
srand(makeSeed());
$randBook = rand(1, 87);
$sql = <<<SQL
\tSELECT *
\tFROM lds_scriptures_books
\tWHERE book_id = {$randBook}
\tLIMIT 1
SQL;
$bookRS = mysql_query($sql) or die("Error in query: " . $sql . " -- " . mysql_error());
$book = mysql_fetch_array($bookRS);
srand(makeSeed());
$randChapter = rand(1, $book['num_chapters']);
header("Location: {$siteroot}/{$book['lds_org']}/{$randChapter}/");