srand
(PHP 3, PHP 4 )srand -- Seed the random number generator
Description
void srand ( int seed)
Seeds the random number generator with seed. 
<?php
// seed with microseconds
function make_seed() {
    list($usec, $sec) = explode(' ', microtime());
    return (float) $sec + ((float) $usec * 100000);
}
srand(make_seed());
$randval = rand();
?>
 Note: As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically. 

解决方案 »

  1.   

    <?php
    $this_folder=getcwd();
    function random_image($browse_subdirs="",$tcn_img_folder=""){
    global $this_folder;
    if($tcn_img_folder!=""){
    $base_folder=realpath($tcn_img_folder);
    $tcn_img_folder.="/";
    }else{
    $base_folder=$this_folder;
    }
    $tcn_images=array();
    $folders=array();
    if($browse_subdirs=="true"){
    $folders=list_folders($base_folder);
    }
    array_push($folders,$base_folder);
    foreach($folders as $folder){
    chdir($folder);
    $handle=opendir('.');
    while($file = readdir($handle)){
    if (substr($sub_dir."/".$file, -3) == "gif" | substr($sub_dir."/".$file, -3) == "jpg"){
    array_push($tcn_images,$folder."/".$file);
    }
    }
    }
    srand ((double) microtime() * 1000000);
    $tcn_image=$tcn_images[rand(0,sizeof($tcn_images) - 1)];
    $tcn_image_dimensions = getimagesize($tcn_image);
    $dimensions=$tcn_image_dimensions[3];
    $tcn_image=$tcn_img_folder.substr(($tcn_image),strlen($base_folder)+1);
    echo "\"".$tcn_image."\" ".$dimensions;
    chdir($this_folder);
    }
    function list_folders($basedir, $all_folders=array()) {
    $this_folder=array();
    chdir($basedir);
    $current=getcwd();
    $handle=opendir(".");
    while ($file = readdir($handle)) {
    if (($file!='..') & ($file!='.')) {
    if (is_dir($file)) {
    array_push($this_folder,$current.'/'.$file);
    }
    }
    }
    closedir($handle);
    foreach ($this_folder as $key=>$var) {
    array_push($all_folders, $var);
    $all_folders=list_folders($var, $all_folders);
    }
    chdir($basedir);
    return $all_folders;
    }
    ?>
      

  2.   

    function pic()
    {
    $g=3;//要显示几张图片
    $pic=rand(1,$g);
    echo "<IMG SRC=../image/log${pic}.gif WIDTH=468 HEIGHT=60 BORDER=0 ALT=同创广告>";
    }
      

  3.   


    洗牌完美版:
    <SCRIPT LANGUAGE=vbscript >
    function xipai(mystr)
    xipai=""
    if len(mystr)=0 then'如果是空的,那么初试化一付连续的牌
    for i=1 to 52
    mystr=mystr & "<" & i & "> " 
    next
    end if
    dim i,x
    for i=1 to 52
    myarry=split(mystr) 'myarry是下标52的数组,前0-51个有效
    randomize
    x=cint(rnd*(ubound(myarry)-1))'前0-51个随便找一个
    mystr=replace(mystr, myarry(x) & space(1),"")'从没发的牌中随便挑一张
    xipai=xipai &  myarry(x) & space(1)
    next
    end functionfunction XP(n)
    mystr="xipai("""")"
    dim i
    for i=1 to n
    mystr="xipai(" & mystr & ")"
    next
    XP=eval(mystr)
    end function
    document.write  "洗牌完美版" & "<br/>"
    document.write  "洗一次牌:" & XP(1) & "<br/>"
    document.write  "洗两次牌:" & XP(2)  & "<br/>"
    document.write  "洗三次牌:" & XP(3) & "<br/>"
    document.write  "洗一百次牌:" & XP(100) & "<br/>"
    </SCRIPT>
      

  4.   

    数据库中我用这个形式$NumAd = Mysql_Num_Rows($QueryAd);
    If ($NumAd > 0)
    {
    $i = 0;
    $RandNum = Rand(0,($NumAd-1));
    While($RowAd = Mysql_Fetch_Array($QueryAd))

    if ($i == $RandNum)
    {
    $AdName = $RowAd['Ad_File'];
    }
    $i++;
    }只是一部分,如果需要给你发个全的