1에서 45까지 랜덤이면서 연속 숫자도 가능한 소스
만약에 연속 숫자도 가능하면서 1 ~ 45 까지 랜덤한 6자리를 10번씩 뽑고자 한다면
[code]
<?php
for ($i = 0; $i < 10; $i++) {
$selected_numbers = array();
while (count($selected_numbers) < 6) {
$number = rand(1, 45); // generate a random number between 1 and 45
if (!in_array($number, $selected_numbers)) { // check if number is already selected
if (count($selected_numbers) > 0 && $number == $selected_numbers[count($selected_numbers) - 1] + 1) {
$selected_numbers[] = $number; // add number to selected numbers if consecutive
} else {
$selected_numbers = array(); // reset the array if non-consecutive number is found
}
}
}
// Print the selected numbers for this set
echo "Set " . ($i + 1) . ": " . implode(" ", $selected_numbers) . "<br>";
}
?>
[/code]
댓글 3개
for( $i=0; $i<6; $i)
$selected_numbers[]=$number+$i;
이런 결과를 말씀하시는 건가요?
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 5186 | PHP |
swallow
|
2년 전 | 943 | |
| 5185 | PHP |
swallow
|
2년 전 | 963 | |
| 5184 | PHP |
swallow
|
2년 전 | 539 | |
| 5183 | PHP |
swallow
|
2년 전 | 848 | |
| 5182 | PHP |
swallow
|
2년 전 | 779 | |
| 5181 | 기타 |
swallow
|
2년 전 | 1022 | |
| 5180 | 2년 전 | 575 | |||
| 5179 | 기타 |
swallow
|
2년 전 | 1437 | |
| 5178 | PHP |
swallow
|
2년 전 | 796 | |
| 5177 | JavaScript |
swallow
|
2년 전 | 1493 | |
| 5176 | PHP |
swallow
|
2년 전 | 1190 | |
| 5175 | 2년 전 | 566 | |||
| 5174 | 기타 | 2년 전 | 817 | ||
| 5173 | PHP |
|
2년 전 | 970 | |
| 5172 | PHP |
|
2년 전 | 1254 | |
| 5171 | 기타 |
그누GPT
|
2년 전 | 1558 | |
| 5170 | PHP |
|
2년 전 | 1056 | |
| 5169 | PHP |
|
2년 전 | 1229 | |
| 5168 | PHP |
|
2년 전 | 1201 | |
| 5167 | JavaScript |
|
2년 전 | 1000 | |
| 5166 | MySQL | 2년 전 | 1195 | ||
| 5165 | MySQL | 2년 전 | 1257 | ||
| 5164 | PHP | 2년 전 | 1504 | ||
| 5163 | OS |
|
2년 전 | 844 | |
| 5162 | 웹서버 |
|
2년 전 | 895 | |
| 5161 | 웹서버 |
|
2년 전 | 977 | |
| 5160 | PHP |
|
2년 전 | 846 | |
| 5159 | PHP |
|
2년 전 | 910 | |
| 5158 | PHP |
|
2년 전 | 919 | |
| 5157 | PHP |
|
2년 전 | 945 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기