아래 댓글에 올린것은 제가 착각한 부분이 있어서 다시 올립니다.
백만건 테스트 거쳣으며 중복 발생하지 않습니다.
//지정된 자릿수의 랜덤한 숫자를 반환합니다. 최대 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년 전 | 360 | ||
| 7929 | 9년 전 | 252 | ||
| 7928 | 9년 전 | 362 | ||
| 7927 | 9년 전 | 288 | ||
| 7926 | 9년 전 | 637 | ||
| 7925 | 9년 전 | 306 | ||
| 7924 | 9년 전 | 270 | ||
| 7923 | 9년 전 | 317 | ||
| 7922 | 9년 전 | 331 | ||
| 7921 | 9년 전 | 368 | ||
| 7920 | 9년 전 | 290 | ||
| 7919 | 9년 전 | 304 | ||
| 7918 | 9년 전 | 471 | ||
| 7917 | 9년 전 | 310 | ||
| 7916 | 9년 전 | 375 | ||
| 7915 | 9년 전 | 356 | ||
| 7914 | 9년 전 | 378 | ||
| 7913 | 9년 전 | 494 | ||
| 7912 | 9년 전 | 369 | ||
| 7911 | 9년 전 | 327 | ||
| 7910 | 9년 전 | 352 | ||
| 7909 | 9년 전 | 460 | ||
| 7908 | 9년 전 | 363 | ||
| 7907 | 9년 전 | 312 | ||
| 7906 | 9년 전 | 327 | ||
| 7905 | 9년 전 | 324 | ||
| 7904 | 9년 전 | 285 | ||
| 7903 | 9년 전 | 283 | ||
| 7902 | 9년 전 | 505 | ||
| 7901 |
|
9년 전 | 712 | |
| 7900 | 9년 전 | 536 | ||
| 7899 | 9년 전 | 340 | ||
| 7898 | 9년 전 | 335 | ||
| 7897 | 9년 전 | 293 | ||
| 7896 | 9년 전 | 312 | ||
| 7895 | 9년 전 | 419 | ||
| 7894 | 9년 전 | 344 | ||
| 7893 | 9년 전 | 269 | ||
| 7892 | 9년 전 | 314 | ||
| 7891 | 9년 전 | 700 | ||
| 7890 | 9년 전 | 1164 | ||
| 7889 | 9년 전 | 726 | ||
| 7888 |
limsy1987
|
9년 전 | 518 | |
| 7887 | 9년 전 | 499 | ||
| 7886 | 9년 전 | 375 | ||
| 7885 | 9년 전 | 354 | ||
| 7884 | 9년 전 | 360 | ||
| 7883 | 9년 전 | 337 | ||
| 7882 | 9년 전 | 351 | ||
| 7881 | 9년 전 | 375 | ||
| 7880 | 9년 전 | 506 | ||
| 7879 | 9년 전 | 408 | ||
| 7878 | 9년 전 | 1143 | ||
| 7877 | 9년 전 | 702 | ||
| 7876 | 9년 전 | 429 | ||
| 7875 | 9년 전 | 499 | ||
| 7874 |
|
9년 전 | 770 | |
| 7873 | 9년 전 | 477 | ||
| 7872 | 9년 전 | 602 | ||
| 7871 | 9년 전 | 439 | ||
| 7870 | 9년 전 | 559 | ||
| 7869 | 9년 전 | 383 | ||
| 7868 | 9년 전 | 368 | ||
| 7867 | 9년 전 | 372 | ||
| 7866 | 9년 전 | 429 | ||
| 7865 | 9년 전 | 391 | ||
| 7864 | 9년 전 | 451 | ||
| 7863 | 9년 전 | 443 | ||
| 7862 | 9년 전 | 421 | ||
| 7861 | 9년 전 | 584 | ||
| 7860 | 9년 전 | 589 | ||
| 7859 | 9년 전 | 360 | ||
| 7858 | 9년 전 | 668 | ||
| 7857 | 9년 전 | 1017 | ||
| 7856 | 9년 전 | 471 | ||
| 7855 | 9년 전 | 691 | ||
| 7854 | 9년 전 | 692 | ||
| 7853 | 9년 전 | 521 | ||
| 7852 | 9년 전 | 466 | ||
| 7851 | 9년 전 | 438 | ||
| 7850 | 9년 전 | 535 | ||
| 7849 | 9년 전 | 310 | ||
| 7848 | 9년 전 | 348 | ||
| 7847 | 9년 전 | 574 | ||
| 7846 | 9년 전 | 399 | ||
| 7845 | 9년 전 | 365 | ||
| 7844 | 9년 전 | 357 | ||
| 7843 | 9년 전 | 365 | ||
| 7842 | 9년 전 | 362 | ||
| 7841 | 9년 전 | 349 | ||
| 7840 | 9년 전 | 353 | ||
| 7839 | 9년 전 | 387 | ||
| 7838 | 9년 전 | 472 | ||
| 7837 | 9년 전 | 314 | ||
| 7836 | 9년 전 | 354 | ||
| 7835 | 9년 전 | 431 | ||
| 7834 |
|
9년 전 | 1166 | |
| 7833 | 9년 전 | 373 | ||
| 7832 | 9년 전 | 359 | ||
| 7831 | 9년 전 | 493 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기