아래 댓글에 올린것은 제가 착각한 부분이 있어서 다시 올립니다.
백만건 테스트 거쳣으며 중복 발생하지 않습니다.
//지정된 자릿수의 랜덤한 숫자를 반환합니다. 최대 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년 전
고맙습니다. 아침부터 힘이 나네요
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 8130 | 9년 전 | 508 | ||
| 8129 |
|
9년 전 | 651 | |
| 8128 | 9년 전 | 519 | ||
| 8127 |
|
9년 전 | 574 | |
| 8126 | 9년 전 | 507 | ||
| 8125 | 9년 전 | 765 | ||
| 8124 |
|
9년 전 | 514 | |
| 8123 | 9년 전 | 499 | ||
| 8122 | 9년 전 | 433 | ||
| 8121 | 9년 전 | 536 | ||
| 8120 | 9년 전 | 464 | ||
| 8119 | 9년 전 | 547 | ||
| 8118 |
|
9년 전 | 629 | |
| 8117 |
|
9년 전 | 398 | |
| 8116 |
PASKRAN
|
9년 전 | 466 | |
| 8115 | 9년 전 | 457 | ||
| 8114 |
kiplayer
|
9년 전 | 596 | |
| 8113 | 9년 전 | 440 | ||
| 8112 |
|
9년 전 | 557 | |
| 8111 | 9년 전 | 406 | ||
| 8110 | 9년 전 | 442 | ||
| 8109 | 9년 전 | 364 | ||
| 8108 |
|
9년 전 | 540 | |
| 8107 |
|
9년 전 | 436 | |
| 8106 |
|
9년 전 | 433 | |
| 8105 | 9년 전 | 474 | ||
| 8104 |
|
9년 전 | 428 | |
| 8103 |
|
9년 전 | 428 | |
| 8102 |
|
9년 전 | 392 | |
| 8101 |
snshero
|
9년 전 | 781 | |
| 8100 | 9년 전 | 835 | ||
| 8099 | 9년 전 | 807 | ||
| 8098 | 9년 전 | 711 | ||
| 8097 | 9년 전 | 513 | ||
| 8096 | 9년 전 | 711 | ||
| 8095 | 9년 전 | 841 | ||
| 8094 | 9년 전 | 511 | ||
| 8093 | 9년 전 | 795 | ||
| 8092 | 9년 전 | 756 | ||
| 8091 | 9년 전 | 1139 | ||
| 8090 | 9년 전 | 764 | ||
| 8089 | 9년 전 | 972 | ||
| 8088 | 9년 전 | 639 | ||
| 8087 | 9년 전 | 759 | ||
| 8086 | 9년 전 | 517 | ||
| 8085 | 9년 전 | 486 | ||
| 8084 | 9년 전 | 608 | ||
| 8083 | 9년 전 | 581 | ||
| 8082 | 9년 전 | 752 | ||
| 8081 | 9년 전 | 468 | ||
| 8080 | 9년 전 | 566 | ||
| 8079 | 9년 전 | 518 | ||
| 8078 | 9년 전 | 447 | ||
| 8077 | 9년 전 | 528 | ||
| 8076 | 9년 전 | 406 | ||
| 8075 | 9년 전 | 437 | ||
| 8074 | 9년 전 | 397 | ||
| 8073 | 9년 전 | 449 | ||
| 8072 | 9년 전 | 441 | ||
| 8071 |
o1o111
|
9년 전 | 891 | |
| 8070 | 9년 전 | 400 | ||
| 8069 | 9년 전 | 335 | ||
| 8068 | 9년 전 | 586 | ||
| 8067 | 9년 전 | 389 | ||
| 8066 | 9년 전 | 424 | ||
| 8065 | 9년 전 | 378 | ||
| 8064 | 9년 전 | 361 | ||
| 8063 | 9년 전 | 335 | ||
| 8062 | 9년 전 | 308 | ||
| 8061 | 9년 전 | 349 | ||
| 8060 | 9년 전 | 388 | ||
| 8059 | 9년 전 | 320 | ||
| 8058 | 9년 전 | 254 | ||
| 8057 | 9년 전 | 383 | ||
| 8056 | 9년 전 | 304 | ||
| 8055 | 9년 전 | 343 | ||
| 8054 | 9년 전 | 362 | ||
| 8053 | 9년 전 | 415 | ||
| 8052 | 9년 전 | 292 | ||
| 8051 | 9년 전 | 330 | ||
| 8050 | 9년 전 | 389 | ||
| 8049 | 9년 전 | 319 | ||
| 8048 | 9년 전 | 432 | ||
| 8047 | 9년 전 | 355 | ||
| 8046 | 9년 전 | 299 | ||
| 8045 | 9년 전 | 255 | ||
| 8044 | 9년 전 | 344 | ||
| 8043 | 9년 전 | 288 | ||
| 8042 | 9년 전 | 293 | ||
| 8041 | 9년 전 | 344 | ||
| 8040 | 9년 전 | 271 | ||
| 8039 | 9년 전 | 317 | ||
| 8038 | 9년 전 | 267 | ||
| 8037 | 9년 전 | 400 | ||
| 8036 | 9년 전 | 483 | ||
| 8035 | 9년 전 | 425 | ||
| 8034 | 9년 전 | 386 | ||
| 8033 | 9년 전 | 348 | ||
| 8032 | 9년 전 | 432 | ||
| 8031 | 9년 전 | 346 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기