100% 꽝을 보장하는 간단한 로또번호 생성 함수
[code]
function select_number($number=array()) {
if(!empty($number) && count($number) === 6) {
return $number;
}
$rand = rand(1,45);
if(empty($number)) {
array_push($number,$rand);
return select_number($number);
} else if( (!in_array($rand,$number) && count($number) < 6)) {
array_push($number,$rand);
return select_number($number);
} else {
return select_number($number);
}
}
$number = ['3','6'];
$select_number = select_number($number);
[/code]
$number 배열에 미리 지정하고 싶은 숫자를 넣어놓으면, 해당 숫자를 포함해서 생성합니다.
지난주 심심해서 사봤는데 꽝이더라구요
댓글 4개
WEBOLUTION
2년 전
[code]function select_numbers($selected_numbers = []) {
$num_numbers_to_select = 6 - count($selected_numbers);
while ($num_numbers_to_select > 0) {
$rand = rand(1, 45);
if (!in_array($rand, $selected_numbers)) {
$selected_numbers[] = $rand;
$num_numbers_to_select--;
}
}
sort($selected_numbers);
return $selected_numbers;
}
$selected_numbers = select_numbers([3, 6]);[/code]
이렇게도 될듯합니다 ^^;
$num_numbers_to_select = 6 - count($selected_numbers);
while ($num_numbers_to_select > 0) {
$rand = rand(1, 45);
if (!in_array($rand, $selected_numbers)) {
$selected_numbers[] = $rand;
$num_numbers_to_select--;
}
}
sort($selected_numbers);
return $selected_numbers;
}
$selected_numbers = select_numbers([3, 6]);[/code]
이렇게도 될듯합니다 ^^;
WEBOLUTION
2년 전
[code]function select_numbers($numbers = []) {
while (count($numbers) < 6) {
$rand = rand(1, 45);
if (!in_array($rand, $numbers)) $numbers[] = $rand;
}
sort($numbers);
return $numbers;
}
$lotto_numbers = select_numbers([1, 3]);[/code]
간단 버전~
while (count($numbers) < 6) {
$rand = rand(1, 45);
if (!in_array($rand, $numbers)) $numbers[] = $rand;
}
sort($numbers);
return $numbers;
}
$lotto_numbers = select_numbers([1, 3]);[/code]
간단 버전~
2년 전
메이드니 간만에 팁 올리셨는데 추천 드립니다.
2년 전
@비타주리 항상 비타님 js 보면서 활력을 얻습니다~
게시판 목록
개발자팁
개발과 관련된 유용한 정보를 공유하세요.
질문은 QA에서 해주시기 바랍니다.
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 5006 | 기타 | 5년 전 | 1916 | ||
| 5005 | 기타 | 5년 전 | 2016 | ||
| 5004 | 기타 | 5년 전 | 2132 | ||
| 5003 | 기타 | 5년 전 | 2806 | ||
| 5002 | 기타 | 5년 전 | 2382 | ||
| 5001 | 기타 | 5년 전 | 2714 | ||
| 5000 | 기타 | 5년 전 | 4763 | ||
| 4999 | 기타 | 5년 전 | 2025 | ||
| 4998 | 기타 | 5년 전 | 2690 | ||
| 4997 | 기타 | 5년 전 | 2734 | ||
| 4996 | 기타 | 5년 전 | 2662 | ||
| 4995 | 기타 | 5년 전 | 2909 | ||
| 4994 | 기타 | 5년 전 | 2163 | ||
| 4993 | 기타 | 5년 전 | 2037 | ||
| 4992 | 기타 | 5년 전 | 1964 | ||
| 4991 | 기타 | 5년 전 | 1978 | ||
| 4990 | 기타 | 5년 전 | 2040 | ||
| 4989 | 기타 | 5년 전 | 2356 | ||
| 4988 | 기타 | 5년 전 | 2050 | ||
| 4987 | 기타 | 5년 전 | 2322 | ||
| 4986 | 기타 | 5년 전 | 2796 | ||
| 4985 | 웹서버 | 5년 전 | 4940 | ||
| 4984 | OS | 5년 전 | 3004 | ||
| 4983 | MySQL | 5년 전 | 2887 | ||
| 4982 | 기타 | 5년 전 | 2003 | ||
| 4981 | PHP | 5년 전 | 2649 | ||
| 4980 | 기타 | 5년 전 | 8967 | ||
| 4979 | 웹서버 | 5년 전 | 3071 | ||
| 4978 | 기타 | 5년 전 | 2047 | ||
| 4977 | PHP | 5년 전 | 3510 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기