srand

(PHP 4, PHP 5, PHP 7)

srand锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟�

说锟斤拷

srand ([ int $seed ] ) : void

锟斤拷 seed 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷印锟�seed 锟斤拷锟斤拷没锟叫革拷锟斤拷时锟斤拷锟结被锟斤拷为锟斤拷时锟斤拷锟斤拷

Note: 锟斤拷 PHP 4.2.0 锟金,诧拷锟斤拷锟斤拷要锟斤拷 srand() 锟斤拷 mt_srand() 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟� 锟斤拷锟斤拷为锟斤拷锟斤拷锟斤拷锟斤拷系统锟皆讹拷锟斤拷傻摹锟�

锟斤拷锟斤拷

seed

锟斤拷选锟斤拷锟斤拷锟斤拷值

锟斤拷锟斤拷值

没锟叫凤拷锟斤拷值锟斤拷

锟斤拷锟斤拷锟斤拷志

锟芥本 说锟斤拷
Since 4.2.0 seed 锟斤拷为锟斤拷选锟斤拷省锟斤拷时锟斤拷默锟斤拷使锟斤拷锟斤拷锟街碉拷锟�

锟斤拷锟斤拷

Example #1 srand() 锟斤拷锟斤拷

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

锟轿硷拷

  • rand() - 锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷锟�
  • getrandmax() - 锟斤拷示锟斤拷锟斤拷锟斤拷锟斤拷目锟斤拷锟街�
  • mt_srand() - 锟斤拷锟斤拷一锟斤拷锟斤拷锟矫碉拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟�