아래 댓글에 올린것은 제가 착각한 부분이 있어서 다시 올립니다.
백만건 테스트 거쳣으며 중복 발생하지 않습니다.
//지정된 자릿수의 랜덤한 숫자를 반환합니다. 최대 10까지 가능합니다. 4 이면 1000 에서 9999 사이의 랜덤 숫자
function get_rand_number($len=4) {
if (empty($len) || !is_int($len)) $len = 4;
else if ($len < 0) $len = abs($len);
if ($len > 10) $len = 10;
return rand(bcpow(10, $len - 1), bcadd(bcpow(10, $len), -1));
}
//지정된 자릿수의 숫자로된 시리얼을 반환합니다. - 를 포함하고 싶지 않을때는 $cut 이 $len 보다 크거나 같으면 됩니다.
function get_serial($len=16, $cut=4, $hipen='-'){
if (empty($len) || !is_int($len)) $len = 16;
else if ($len < 0) $len = abs($len);
if (empty($cut) || !is_int($cut)) $cut = 4;
else if ($cut < 0) $cut = abs($cut);
list($usec, $sec) = explode(' ', microtime());
$serial = str_replace('.', '', (string)bcmul(bcmul((float)$usec * 10000000 , (float)$sec) , get_rand_number(4)));
$serial_length = strlen($serial);
$sub = $len - $serial_length;
if ($sub > 0) $serial .= (string)get_rand_number($sub);
else if ($sub < 0) $serial = substr($serial, 0, $len);
return preg_replace("`([0-9]{" . $cut . "})`", "$1" . $hipen, $serial, floor($len / $cut) - 1);
}
function get_rand_number($len=4) {
if (empty($len) || !is_int($len)) $len = 4;
else if ($len < 0) $len = abs($len);
if ($len > 10) $len = 10;
return rand(bcpow(10, $len - 1), bcadd(bcpow(10, $len), -1));
}
//지정된 자릿수의 숫자로된 시리얼을 반환합니다. - 를 포함하고 싶지 않을때는 $cut 이 $len 보다 크거나 같으면 됩니다.
function get_serial($len=16, $cut=4, $hipen='-'){
if (empty($len) || !is_int($len)) $len = 16;
else if ($len < 0) $len = abs($len);
if (empty($cut) || !is_int($cut)) $cut = 4;
else if ($cut < 0) $cut = abs($cut);
list($usec, $sec) = explode(' ', microtime());
$serial = str_replace('.', '', (string)bcmul(bcmul((float)$usec * 10000000 , (float)$sec) , get_rand_number(4)));
$serial_length = strlen($serial);
$sub = $len - $serial_length;
if ($sub > 0) $serial .= (string)get_rand_number($sub);
else if ($sub < 0) $serial = substr($serial, 0, $len);
return preg_replace("`([0-9]{" . $cut . "})`", "$1" . $hipen, $serial, floor($len / $cut) - 1);
}
댓글 9개
13년 전
참고로
get_rand_number(4) 를 곱하는 이유는
제일 앞자리가 랜덤으로 나오게 하기 위함입니다.
get_rand_number(4) 를 곱하는 이유는
제일 앞자리가 랜덤으로 나오게 하기 위함입니다.
13년 전
아직 할건 아니고 말로만 오가는 건이 하나 있어서 혼자 가끔 고민하고 있었는데 바로 일들어 가도 되겠네요. 감사합니다.
13년 전
네에 도움이 되셧으면 합니다.
13년 전
감사합니다. 너무 고생하셨네요 ^^ 추천날리고 갑니다 ㅎㅎ
13년 전
네에 감사합니다.
13년 전
유창화님 글에 자동으로 추천하는 함수는 없나요?
13년 전
과찬이십니다.
똥싼너구리
13년 전
우오 멋집니다!
저는 보통 대충 만들어서 중복검사 해버리고 마는데..
꼼꼼하십니다!!
저는 보통 대충 만들어서 중복검사 해버리고 마는데..
꼼꼼하십니다!!
13년 전
고맙습니다. 아침부터 힘이 나네요
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7830 | 9년 전 | 437 | ||
| 7829 |
|
9년 전 | 623 | |
| 7828 | 10년 전 | 551 | ||
| 7827 | 10년 전 | 446 | ||
| 7826 | 10년 전 | 451 | ||
| 7825 | 10년 전 | 492 | ||
| 7824 | 10년 전 | 454 | ||
| 7823 | 10년 전 | 398 | ||
| 7822 | 10년 전 | 373 | ||
| 7821 | 10년 전 | 320 | ||
| 7820 | 10년 전 | 357 | ||
| 7819 |
|
10년 전 | 754 | |
| 7818 | 10년 전 | 402 | ||
| 7817 | 10년 전 | 535 | ||
| 7816 | 10년 전 | 421 | ||
| 7815 | 10년 전 | 620 | ||
| 7814 | 10년 전 | 447 | ||
| 7813 | 10년 전 | 398 | ||
| 7812 | 10년 전 | 412 | ||
| 7811 | 10년 전 | 401 | ||
| 7810 | 10년 전 | 582 | ||
| 7809 | 10년 전 | 514 | ||
| 7808 | 10년 전 | 386 | ||
| 7807 | 10년 전 | 418 | ||
| 7806 |
프로그래머7
|
10년 전 | 1343 | |
| 7805 | 10년 전 | 1287 | ||
| 7804 |
zahir1312
|
10년 전 | 789 | |
| 7803 |
|
10년 전 | 1383 | |
| 7802 | 10년 전 | 472 | ||
| 7801 | 10년 전 | 869 | ||
| 7800 | 10년 전 | 1090 | ||
| 7799 | 10년 전 | 567 | ||
| 7798 | 10년 전 | 522 | ||
| 7797 | 10년 전 | 526 | ||
| 7796 | 10년 전 | 368 | ||
| 7795 | 10년 전 | 518 | ||
| 7794 | 10년 전 | 567 | ||
| 7793 | 10년 전 | 1065 | ||
| 7792 | 10년 전 | 490 | ||
| 7791 | 10년 전 | 568 | ||
| 7790 | 10년 전 | 520 | ||
| 7789 |
fbastore
|
10년 전 | 1457 | |
| 7788 | 10년 전 | 559 | ||
| 7787 | 10년 전 | 416 | ||
| 7786 | 10년 전 | 607 | ||
| 7785 | 10년 전 | 599 | ||
| 7784 | 10년 전 | 656 | ||
| 7783 | 10년 전 | 465 | ||
| 7782 | 10년 전 | 502 | ||
| 7781 | 10년 전 | 910 | ||
| 7780 | 10년 전 | 829 | ||
| 7779 | 10년 전 | 780 | ||
| 7778 | 10년 전 | 369 | ||
| 7777 | 10년 전 | 472 | ||
| 7776 | 10년 전 | 468 | ||
| 7775 | 10년 전 | 416 | ||
| 7774 | 10년 전 | 637 | ||
| 7773 | 10년 전 | 394 | ||
| 7772 | 10년 전 | 748 | ||
| 7771 | 10년 전 | 400 | ||
| 7770 | 10년 전 | 654 | ||
| 7769 | 10년 전 | 402 | ||
| 7768 | 10년 전 | 624 | ||
| 7767 | 10년 전 | 1184 | ||
| 7766 | 10년 전 | 501 | ||
| 7765 | 10년 전 | 549 | ||
| 7764 |
잘살아보자
|
10년 전 | 404 | |
| 7763 |
|
10년 전 | 1471 | |
| 7762 |
Tosea
|
10년 전 | 1068 | |
| 7761 | 10년 전 | 663 | ||
| 7760 |
잘살아보자
|
10년 전 | 698 | |
| 7759 |
잘살아보자
|
10년 전 | 527 | |
| 7758 |
잘살아보자
|
10년 전 | 606 | |
| 7757 | 10년 전 | 1250 | ||
| 7756 |
ITBANK
|
10년 전 | 1267 | |
| 7755 | 10년 전 | 1936 | ||
| 7754 | 10년 전 | 1064 | ||
| 7753 | 10년 전 | 896 | ||
| 7752 | 10년 전 | 1408 | ||
| 7751 |
잘살아보자
|
10년 전 | 548 | |
| 7750 |
잘살아보자
|
10년 전 | 490 | |
| 7749 |
잘살아보자
|
10년 전 | 499 | |
| 7748 |
잘살아보자
|
10년 전 | 513 | |
| 7747 |
잘살아보자
|
10년 전 | 603 | |
| 7746 |
잘살아보자
|
10년 전 | 688 | |
| 7745 |
잘살아보자
|
10년 전 | 927 | |
| 7744 |
잘살아보자
|
10년 전 | 426 | |
| 7743 | 10년 전 | 959 | ||
| 7742 |
starbros
|
10년 전 | 850 | |
| 7741 |
잘살아보자
|
10년 전 | 682 | |
| 7740 |
잘살아보자
|
10년 전 | 556 | |
| 7739 |
잘살아보자
|
10년 전 | 472 | |
| 7738 |
잘살아보자
|
10년 전 | 548 | |
| 7737 |
잘살아보자
|
10년 전 | 520 | |
| 7736 |
잘살아보자
|
10년 전 | 536 | |
| 7735 |
잘살아보자
|
10년 전 | 862 | |
| 7734 |
잘살아보자
|
10년 전 | 438 | |
| 7733 |
잘살아보자
|
10년 전 | 551 | |
| 7732 |
잘살아보자
|
10년 전 | 710 | |
| 7731 |
잘살아보자
|
10년 전 | 630 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기