当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > srand() 函数

PHP
php 无限分类的实现
常用PHP代码
windows下安装配置php视频教程
MySQL数据库结构和数据的导出和导入
PHP实现 IP Whois 查询
PHP5 this,self和parent关键字详解
PHP 安全技巧连载 #1[译]
PHP 安全技巧连载 #2[译]
PHP 安全技巧连载 #3[译]
PHP 安全技巧连载 #4[译]
PHP 安全技巧连载 #5[译]
PHP 安全技巧连载 #6[译]
PHP 安全技巧连载 #7[译]
PHP 安全技巧连载 #8[译]
PHP 安全技巧连载 #9[译]
PHP 安全技巧连载 #10[译]
PHP 安全技巧连载 #11[译]
PHP error_reporting的使用
PHP 安全技巧连载 #12
使用PHP做Linux/Unix守护进程

PHP 中的 srand() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 582 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The srand() function seeds the random number generator for rand().
srand()函数的作用是:播下一个随机数发生器[random number generator]的种子。

This function should be called only once per script, and it must be called before any calls to rand().
这个函数最好在一个脚本中只请求一次,而且,最好是在请求rand()函数之前请求它。

Syntax
语法

srand(seed)

Parameter
参数
Description
描述
seed Optional. Seed number for the random number generator. If omitted, a random value is used.
可选参数。为随机数发生器[random number generator]播下一颗数值种子。如果忽略该参数,那么将使用随机值


Tips and Notes
提示和注意点

Note: In PHP 4.2.0 and later, there is no need to seed the random generator with srand(). This is done automatically.
注意:在PHP 4.2.0及其以上版本中,你不需要给mt_srand()函数指定种子,因为它是自动完成的。

Tip: The greater the randomness of the seed, the more random number you'll get. A suitable number to seed this function with, is mktime().
提示:如果你随意的播种,那么你所获得的数字的随机性将会更大。你可以使用mktime()函数为该函数指定一颗较为合适的种子。


Example
案例

In this example we will seed the random number generator:
在下面的案例中,我们将为随机数发生器[random number generator]播下一颗数值种子:

<?php
srand(mktime());
echo(rand());
?>

The output of the code above could be:
上述代码将输出下面的结果:

14054

评论 (0) All

登陆 | 还没注册?