int rand ( [int min, int max])
PHP 에서 난수를 발생할때 사용하는 rand() 함수입니다. rand 함수의 기본 인자인 min, max를 생략하고 호출하면 rand() 함수는 0과 RAND_MAX 사이의 임의의 난수를 반환하게 됩니다. RAND_MAX값은 32비트 운영체제에서는 32768까지입니다( 32비트 운영체제의 integer 형의 범위와 같습니다 )
1부터 10사이의 난수를 얻으려면 rand( 1, 10) 과 같이 사용하시면 되며 PHP4.2 버전 이후부터는 SEED값을 줄 필요가 없습니다.
<? $url_cnt = rand(0,4);
switch ($url_cnt){ case "0"; echo "<script>location.href = 'index/main0.html';</script>"; exit; break;
case "1": echo "<script>location.href = 'index/main1.html';</script>"; exit; break;
case "2": echo "<script>location.href = 'index/main2.html';</script>"; exit; break;
case "3": echo "<script>location.href = 'index/main3.html';</script>"; exit; break; case "4": echo "<script>location.href = 'index/main4.html';</script>"; exit; break; }
?> |
|
|