아래 댓글에 올린것은 제가 착각한 부분이 있어서 다시 올립니다.
백만건 테스트 거쳣으며 중복 발생하지 않습니다.
//지정된 자릿수의 랜덤한 숫자를 반환합니다. 최대 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년 전
고맙습니다. 아침부터 힘이 나네요
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7930 | 9년 전 | 423 | ||
| 7929 | 9년 전 | 352 | ||
| 7928 | 9년 전 | 440 | ||
| 7927 | 9년 전 | 357 | ||
| 7926 | 9년 전 | 675 | ||
| 7925 | 9년 전 | 381 | ||
| 7924 | 9년 전 | 365 | ||
| 7923 | 9년 전 | 359 | ||
| 7922 | 9년 전 | 395 | ||
| 7921 | 9년 전 | 413 | ||
| 7920 | 9년 전 | 332 | ||
| 7919 | 9년 전 | 342 | ||
| 7918 | 9년 전 | 498 | ||
| 7917 | 9년 전 | 350 | ||
| 7916 | 9년 전 | 424 | ||
| 7915 | 9년 전 | 427 | ||
| 7914 | 9년 전 | 436 | ||
| 7913 | 9년 전 | 601 | ||
| 7912 | 9년 전 | 445 | ||
| 7911 | 9년 전 | 380 | ||
| 7910 | 9년 전 | 422 | ||
| 7909 | 9년 전 | 531 | ||
| 7908 | 9년 전 | 452 | ||
| 7907 | 9년 전 | 394 | ||
| 7906 | 9년 전 | 412 | ||
| 7905 | 9년 전 | 390 | ||
| 7904 | 9년 전 | 377 | ||
| 7903 | 9년 전 | 368 | ||
| 7902 | 9년 전 | 573 | ||
| 7901 |
|
9년 전 | 755 | |
| 7900 | 9년 전 | 615 | ||
| 7899 | 9년 전 | 407 | ||
| 7898 | 9년 전 | 409 | ||
| 7897 | 9년 전 | 365 | ||
| 7896 | 9년 전 | 376 | ||
| 7895 | 9년 전 | 489 | ||
| 7894 | 9년 전 | 411 | ||
| 7893 | 9년 전 | 367 | ||
| 7892 | 9년 전 | 415 | ||
| 7891 | 9년 전 | 784 | ||
| 7890 | 9년 전 | 1212 | ||
| 7889 | 9년 전 | 755 | ||
| 7888 |
limsy1987
|
9년 전 | 562 | |
| 7887 | 9년 전 | 582 | ||
| 7886 | 9년 전 | 475 | ||
| 7885 | 9년 전 | 429 | ||
| 7884 | 9년 전 | 431 | ||
| 7883 | 9년 전 | 431 | ||
| 7882 | 9년 전 | 482 | ||
| 7881 | 9년 전 | 462 | ||
| 7880 | 9년 전 | 597 | ||
| 7879 | 9년 전 | 483 | ||
| 7878 | 9년 전 | 1242 | ||
| 7877 | 9년 전 | 774 | ||
| 7876 | 9년 전 | 507 | ||
| 7875 | 9년 전 | 582 | ||
| 7874 |
|
9년 전 | 822 | |
| 7873 | 9년 전 | 533 | ||
| 7872 | 9년 전 | 693 | ||
| 7871 | 9년 전 | 499 | ||
| 7870 | 9년 전 | 628 | ||
| 7869 | 9년 전 | 447 | ||
| 7868 | 9년 전 | 474 | ||
| 7867 | 9년 전 | 458 | ||
| 7866 | 9년 전 | 518 | ||
| 7865 | 9년 전 | 469 | ||
| 7864 | 9년 전 | 531 | ||
| 7863 | 9년 전 | 529 | ||
| 7862 | 9년 전 | 482 | ||
| 7861 | 9년 전 | 668 | ||
| 7860 | 9년 전 | 641 | ||
| 7859 | 9년 전 | 430 | ||
| 7858 | 9년 전 | 719 | ||
| 7857 | 9년 전 | 1101 | ||
| 7856 | 9년 전 | 546 | ||
| 7855 | 9년 전 | 774 | ||
| 7854 | 9년 전 | 738 | ||
| 7853 | 9년 전 | 599 | ||
| 7852 | 9년 전 | 534 | ||
| 7851 | 9년 전 | 530 | ||
| 7850 | 9년 전 | 606 | ||
| 7849 | 9년 전 | 374 | ||
| 7848 | 9년 전 | 434 | ||
| 7847 | 9년 전 | 678 | ||
| 7846 | 9년 전 | 470 | ||
| 7845 | 9년 전 | 442 | ||
| 7844 | 9년 전 | 412 | ||
| 7843 | 9년 전 | 437 | ||
| 7842 | 9년 전 | 420 | ||
| 7841 | 9년 전 | 402 | ||
| 7840 | 9년 전 | 419 | ||
| 7839 | 9년 전 | 451 | ||
| 7838 | 9년 전 | 526 | ||
| 7837 | 9년 전 | 373 | ||
| 7836 | 9년 전 | 419 | ||
| 7835 | 9년 전 | 492 | ||
| 7834 |
|
9년 전 | 1205 | |
| 7833 | 9년 전 | 454 | ||
| 7832 | 9년 전 | 437 | ||
| 7831 | 9년 전 | 585 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기