PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<sqrttan>
Last updated: Mon, 16 Jul 2012

srand

(PHP 3, PHP 4, PHP 5)

srand -- 播下随机数发生器种子

说明

void srand ( int seed )

seed 播下随机数发生器种子。

<?php
// seed with microseconds
function make_seed() {
   list(
$usec, $sec) = explode(' ', microtime());
   return (float)
$sec + ((float) $usec * 100000);
}
srand(make_seed());
$randval = rand();
?>

注: 自 PHP 4.2.0 起,不再需要用 srand()mt_srand() 函数给随机数生成器播种,现已自动完成。

参见 rand()getrandmax()mt_srand()




<sqrttan>
 Last updated: Mon, 16 Jul 2012
 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://manual.phpv.net/
Last updated: Thu Jul 7 19:13:47 2005 CST