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에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 5396 | 기타 |
슈퍼스타맨
|
3개월 전 | 333 | |
| 5395 | PHP |
untitled
|
4개월 전 | 807 | |
| 5394 | MySQL |
선택과집중
|
5개월 전 | 579 | |
| 5393 | 웹서버 |
techstar
|
7개월 전 | 848 | |
| 5392 |
|
1년 전 | 1204 | ||
| 5391 | 9개월 전 | 1108 | |||
| 5390 | 9개월 전 | 892 | |||
| 5389 | 8개월 전 | 863 | |||
| 5388 | 8개월 전 | 963 | |||
| 5387 | 7개월 전 | 794 | |||
| 5386 | JavaScript |
nekoieye
|
7개월 전 | 957 | |
| 5385 | 웹서버 | 7개월 전 | 977 | ||
| 5384 | JavaScript |
|
8개월 전 | 800 | |
| 5383 | 기타 | 9개월 전 | 1115 | ||
| 5382 | 기타 |
|
9개월 전 | 566 | |
| 5381 | JavaScript | 9개월 전 | 895 | ||
| 5380 | 기타 |
|
9개월 전 | 675 | |
| 5379 | JavaScript | 9개월 전 | 678 | ||
| 5378 | 10개월 전 | 1187 | |||
| 5377 | 기타 |
|
10개월 전 | 748 | |
| 5376 | jQuery |
|
10개월 전 | 558 | |
| 5375 | jQuery |
techstar
|
10개월 전 | 717 | |
| 5374 | 기타 |
|
10개월 전 | 765 | |
| 5373 | MySQL |
|
11개월 전 | 798 | |
| 5372 | 기타 |
|
11개월 전 | 1000 | |
| 5371 | JavaScript |
|
11개월 전 | 711 | |
| 5370 | JavaScript |
|
11개월 전 | 717 | |
| 5369 | PHP |
|
11개월 전 | 1228 | |
| 5368 | PHP | 11개월 전 | 1396 | ||
| 5367 | 기타 |
nekoieye
|
1년 전 | 1270 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기