Forum und email

srand

(PHP 4, PHP 5)

srand — 난수 생성기를 초기화합니다.

설명

void srand ([ int $seed ] )

seed 로 난수 생성기를 초기화합니다. PHP 4.2.0부터 seed 는 선택적이 되었고, 생략할 경우에도 기본값으로 난수값을 생성합니다.

Example#1 srand() 예제

// 마이크로초로 초기화
function make_seed()
{
    list($usec, $sec) = explode(' ', microtime());
    return (float) $sec + ((float) $usec * 100000);
}
srand(make_seed());
$randval = rand();

Note: PHP 4.2.0부터 srand()mt_srand()를 이용한 난수값 생성기 초기화를 할 필요가 없습니다. 자동적으로 이루어집니다.

참고: rand(), getrandmax(), mt_srand().