아래 댓글에 올린것은 제가 착각한 부분이 있어서 다시 올립니다.
백만건 테스트 거쳣으며 중복 발생하지 않습니다.
//지정된 자릿수의 랜덤한 숫자를 반환합니다. 최대 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년 전
고맙습니다. 아침부터 힘이 나네요
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7630 | 10년 전 | 633 | ||
| 7629 |
|
10년 전 | 2339 | |
| 7628 | 10년 전 | 768 | ||
| 7627 |
|
10년 전 | 997 | |
| 7626 |
|
10년 전 | 1756 | |
| 7625 | 10년 전 | 656 | ||
| 7624 | 10년 전 | 681 | ||
| 7623 |
|
10년 전 | 3002 | |
| 7622 | 10년 전 | 684 | ||
| 7621 |
leeleeleelee
|
10년 전 | 565 | |
| 7620 | 10년 전 | 524 | ||
| 7619 | 10년 전 | 449 | ||
| 7618 | 10년 전 | 994 | ||
| 7617 | 10년 전 | 712 | ||
| 7616 | 10년 전 | 606 | ||
| 7615 | 10년 전 | 701 | ||
| 7614 | 10년 전 | 1207 | ||
| 7613 |
|
10년 전 | 2047 | |
| 7612 | 10년 전 | 1116 | ||
| 7611 | 10년 전 | 1380 | ||
| 7610 |
|
10년 전 | 1872 | |
| 7609 |
|
10년 전 | 1288 | |
| 7608 |
mwdkim
|
10년 전 | 1092 | |
| 7607 |
|
10년 전 | 1020 | |
| 7606 |
mwdkim
|
10년 전 | 3897 | |
| 7605 | 10년 전 | 664 | ||
| 7604 | 10년 전 | 1002 | ||
| 7603 | 10년 전 | 1626 | ||
| 7602 |
|
10년 전 | 1041 | |
| 7601 |
AniNest
|
10년 전 | 2758 | |
| 7600 |
port443
|
10년 전 | 990 | |
| 7599 | 10년 전 | 915 | ||
| 7598 | 10년 전 | 988 | ||
| 7597 | 10년 전 | 4550 | ||
| 7596 |
SeungYeon
|
10년 전 | 865 | |
| 7595 |
untitled
|
10년 전 | 2386 | |
| 7594 |
프로그래머7
|
10년 전 | 1700 | |
| 7593 |
untitled
|
10년 전 | 2337 | |
| 7592 |
untitled
|
10년 전 | 1908 | |
| 7591 |
untitled
|
10년 전 | 2647 | |
| 7590 |
아리마2001
|
10년 전 | 820 | |
| 7589 | 10년 전 | 1078 | ||
| 7588 |
|
10년 전 | 2894 | |
| 7587 | 10년 전 | 1272 | ||
| 7586 | 10년 전 | 631 | ||
| 7585 | 10년 전 | 1655 | ||
| 7584 | 10년 전 | 1388 | ||
| 7583 |
leeleeleelee
|
10년 전 | 1122 | |
| 7582 |
|
10년 전 | 1070 | |
| 7581 | 10년 전 | 1302 | ||
| 7580 | 10년 전 | 942 | ||
| 7579 |
|
10년 전 | 579 | |
| 7578 | 10년 전 | 1387 | ||
| 7577 |
|
10년 전 | 1850 | |
| 7576 | 10년 전 | 1365 | ||
| 7575 |
멋진남자임
|
10년 전 | 1445 | |
| 7574 | 10년 전 | 2084 | ||
| 7573 | 10년 전 | 3212 | ||
| 7572 | 10년 전 | 745 | ||
| 7571 |
|
10년 전 | 770 | |
| 7570 |
|
10년 전 | 1286 | |
| 7569 | 10년 전 | 1519 | ||
| 7568 |
this1mg
|
10년 전 | 1021 | |
| 7567 |
|
10년 전 | 729 | |
| 7566 | 10년 전 | 888 | ||
| 7565 |
Angel하늘
|
10년 전 | 961 | |
| 7564 |
seoldi
|
10년 전 | 1195 | |
| 7563 |
|
10년 전 | 1345 | |
| 7562 |
멋진남자임
|
10년 전 | 2042 | |
| 7561 | 10년 전 | 679 | ||
| 7560 |
leeleeleelee
|
10년 전 | 877 | |
| 7559 | 10년 전 | 5008 | ||
| 7558 |
RinaP
|
10년 전 | 753 | |
| 7557 |
|
10년 전 | 1217 | |
| 7556 | 10년 전 | 1168 | ||
| 7555 |
hyohyojj1234
|
10년 전 | 1633 | |
| 7554 | 10년 전 | 1068 | ||
| 7553 |
senseme
|
10년 전 | 1321 | |
| 7552 |
ehdltdoit
|
10년 전 | 1413 | |
| 7551 |
|
10년 전 | 1794 | |
| 7550 |
leeleeleelee
|
10년 전 | 1558 | |
| 7549 | 10년 전 | 2393 | ||
| 7548 | 10년 전 | 1812 | ||
| 7547 |
멋진남자임
|
10년 전 | 1921 | |
| 7546 | 10년 전 | 964 | ||
| 7545 |
ILMare1003
|
10년 전 | 1254 | |
| 7544 |
|
10년 전 | 1210 | |
| 7543 | 10년 전 | 860 | ||
| 7542 | 10년 전 | 635 | ||
| 7541 |
울라라라우
|
10년 전 | 846 | |
| 7540 | 10년 전 | 1578 | ||
| 7539 | 10년 전 | 897 | ||
| 7538 |
|
10년 전 | 1807 | |
| 7537 | 10년 전 | 3587 | ||
| 7536 |
Gaumi
|
10년 전 | 1379 | |
| 7535 |
프로그램은어려워
|
10년 전 | 1241 | |
| 7534 |
senseme
|
10년 전 | 1191 | |
| 7533 | 10년 전 | 1165 | ||
| 7532 | 10년 전 | 833 | ||
| 7531 | 10년 전 | 2025 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기