有。rand
本函式用来取得乱数值。若没有指定乱数的最大及最小范围,本函式会自动的从 0 到 RAND_MAX 中取一个乱数。若有指定 min 及 max 的参数,则从指定参数中取一个数字。例如 rand(38, 49) 则会从 38 到 49 之间取一个乱数值,UNIX 系统包含 49、Win32 系统不包含 49 ([email protected] 10-May-1999)。值得注意的是为使乱数的乱度最大,每次在取乱数之前最好使用 srand() 以设定新的乱数种子。

解决方案 »

  1.   

    rand
    (PHP 3, PHP 4 )rand -- 产生一个随机数
    说明
    int rand ( [int min, int max])
    如果没有提供可选参数 min 和 max,rand() 返回 0 到 RAND_MAX 之间的伪随机数。例如想要 5 到 15(包括 5 和 15)之间的随机数,用 rand(5, 15)。 在 PHP 较早版本中,必须在使用本函数之前调用 srand() 播下随机数种子。自 4.2.0 不再需要这样做了。 注: 在 3.0.7 之前的版本中,max 的含义是 range。要在这些版本中得到和上例相同 5 到 15 的随机数,简短的例子是 rand (5, 11)。 参见 srand(),getrandmax() 和 mt_rand()。 
    mt_rand
    (PHP 3>= 3.0.6, PHP 4 )mt_rand -- 生成更好的随机数
    说明
    int mt_rand ( [int min, int max])
    很多老的 libc 的随机数发生器具有一些不确定和未知的特性而且很慢。PHP 的 rand() 函数默认使用 libc 随机数发生器。mt_rand() 函数是非正式用来替换它的。该函数用了 Mersenne Twister 中已知的特性作为随机数发生器,它可以产生可作为某些加密算法种子的随机数(细节见主页)而且比通常 libc 提供的速度快四倍。 如果没有提供可选参数 min 和 max,mt_rand() 返回 0 到 RAND_MAX 之间的伪随机数。例如想要 5 到 15(包括 5 和 15)之间的随机数,用 mt_rand(5, 15)。 在 PHP 较早版本中,必须在使用本函数之前调用 mt_srand() 播下随机数种子。自 4.2.0 不再需要这样做了。 注: 在 3.0.7 之前的版本中,max 的含义是 range。要在这些版本中得到和上例相同 5 到 15 的随机数,简短的例子是 mt_rand (5, 11)。 参见 mt_srand(),mt_getrandmax() 和 rand()。 
      

  2.   

    rand
    (PHP 3, PHP 4 )rand -- Generate a random value
    Description
    int rand ( [int min, int max])
    If called without the optional min, max arguments rand() returns a pseudo-random value between 0 and RAND_MAX. If you want a random number between 5 and 15 (inclusive), for example, use rand (5, 15). In older versions of PHP, you had to seed the random number generator before use with srand(). Since 4.2.0 this is no longer necessary. Note: In versions before 3.0.7 the meaning of max was range. To get the same results in these versions the short example should be rand (5, 11) to get a random number between 5 and 15. See also srand(), getrandmax(), and mt_rand(). 
      

  3.   

    还有相关的
    srand
    设定乱数种子。
    语法: void srand(int seed);
    传回值: 无
    函式种类: 数学运算 
    内容说明 
    本函式传入参数 seed 后,设定乱数的种子。值得注意的是参数 seed 值最好也是随机出现的数字,例如利用加入时间做为变数的来源就是不错的方法,或者开发其它的硬体周边介面可取得更好的乱数。
    使用范例 
    本例加入时间的因素,以执行时的百万分之一秒当乱数种子<?php
    srand((double)microtime()*1000000);
    $randval = rand();
    echo $randval;
    ?> 
      

  4.   

    偶写的一个随机函数
    function make_seed() {
        list($usec, $sec) = explode(' ', microtime());
        return (float) $sec + ((float) $usec * 100000);
    }function getRam($length,&$sessioncode) {
    /*total 35 chars*/
    $source_chars = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    srand(make_seed());
    $str = "";
    for($i=0;$i<$length;$i++){
    $j = rand(1,(strlen($source_chars)-1));
    $str = $str.$source_chars[$j];
    }
    $returnvalue = str_shuffle($str);
    $sessioncode = $returnvalue;
    return $sessioncode;
    }
      

  5.   

    srand((double)microtime()*1000000);
    $a=rand();