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에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 5036 | 웹서버 | 4년 전 | 2138 | ||
| 5035 | 웹서버 | 4년 전 | 2165 | ||
| 5034 | 웹서버 | 4년 전 | 2397 | ||
| 5033 | 웹서버 | 4년 전 | 1776 | ||
| 5032 | 웹서버 | 4년 전 | 2131 | ||
| 5031 | 웹서버 | 4년 전 | 2511 | ||
| 5030 | MySQL | 4년 전 | 2880 | ||
| 5029 | 웹서버 | 4년 전 | 7175 | ||
| 5028 | 웹서버 |
kerimdoor
|
4년 전 | 1628 | |
| 5027 | OS | 4년 전 | 6550 | ||
| 5026 | PHP |
|
4년 전 | 4637 | |
| 5025 | JavaScript |
|
4년 전 | 2401 | |
| 5024 | MySQL |
|
4년 전 | 3810 | |
| 5023 | MySQL | 4년 전 | 3027 | ||
| 5022 | PHP | 4년 전 | 2320 | ||
| 5021 | PHP |
|
4년 전 | 3247 | |
| 5020 | PHP | 4년 전 | 4301 | ||
| 5019 | PHP | 5년 전 | 4324 | ||
| 5018 | 웹서버 | 5년 전 | 6701 | ||
| 5017 | 기타 |
HappyTank
|
5년 전 | 5066 | |
| 5016 | MySQL | 5년 전 | 3082 | ||
| 5015 | 기타 | 5년 전 | 2269 | ||
| 5014 | 기타 | 5년 전 | 2831 | ||
| 5013 | 기타 | 5년 전 | 2251 | ||
| 5012 | 기타 | 5년 전 | 2258 | ||
| 5011 | 기타 | 5년 전 | 2211 | ||
| 5010 | 기타 | 5년 전 | 1770 | ||
| 5009 | 기타 | 5년 전 | 2378 | ||
| 5008 | 기타 | 5년 전 | 2008 | ||
| 5007 | 기타 | 5년 전 | 1971 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기