<?php
$rand = (float)rand()/(float)getrandmax();
if ($rand < 0.33) {
?>
내용
<?php
} else if ($rand < 0.34) {
?>
내용
<?php
} else {
?>
내용
<?php
}
?>
이렇게 하면 안되는 이유는 뭐죠? 3개를 랜덤하게 33% 확률(한개는 34%)로 1개씩 뽑아낼려면 어떻게 해야 할까요?
|
답변 1개 / 댓글 4개
채택된 답변
+20 포인트
답변에 대한 댓글 4개
되네요. 감사합니다.
<?php
$rand = (float)rand()/(float)getrandmax();
if ($rand < 0.33) {
?>
내용
<?php
$rand = (float)rand()/(float)getrandmax();
} else if ($rand < 0.67) {
?>
내용
<?php
$rand = (float)rand()/(float)getrandmax();
} else if ($rand < 1) {
?>
내용
<?php
}
?>
이렇게 하는거죠?
<?php
$rand = (float)rand()/(float)getrandmax();
if ($rand < 0.33) {
?>
내용
<?php
$rand = (float)rand()/(float)getrandmax();
} else if ($rand < 0.67) {
?>
내용
<?php
$rand = (float)rand()/(float)getrandmax();
} else if ($rand < 1) {
?>
내용
<?php
}
?>
이렇게 하는거죠?
답변을 작성하려면 로그인이 필요합니다.