아래 댓글에 올린것은 제가 착각한 부분이 있어서 다시 올립니다.
백만건 테스트 거쳣으며 중복 발생하지 않습니다.
//지정된 자릿수의 랜덤한 숫자를 반환합니다. 최대 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년 전
고맙습니다. 아침부터 힘이 나네요
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 4530 |
라이언31
|
13년 전 | 650 | |
| 4529 | 13년 전 | 807 | ||
| 4528 |
꼬꼬아부지
|
13년 전 | 1009 | |
| 4527 | 13년 전 | 619 | ||
| 4526 | 13년 전 | 701 | ||
| 4525 |
|
13년 전 | 1026 | |
| 4524 | 13년 전 | 1002 | ||
| 4523 | 13년 전 | 2297 | ||
| 4522 | 13년 전 | 616 | ||
| 4521 | 13년 전 | 1264 | ||
| 4520 | 13년 전 | 1552 | ||
| 4519 |
복이219
|
13년 전 | 1208 | |
| 4518 | 13년 전 | 497 | ||
| 4517 | 13년 전 | 1297 | ||
| 4516 |
아이피마스터
|
13년 전 | 557 | |
| 4515 | 13년 전 | 653 | ||
| 4514 | 13년 전 | 650 | ||
| 4513 | 13년 전 | 1082 | ||
| 4512 |
ananom
|
13년 전 | 4367 | |
| 4511 |
ananom
|
13년 전 | 1481 | |
| 4510 | 13년 전 | 1225 | ||
| 4509 | 13년 전 | 692 | ||
| 4508 | 13년 전 | 851 | ||
| 4507 | 13년 전 | 938 | ||
| 4506 | 13년 전 | 709 | ||
| 4505 | 13년 전 | 639 | ||
| 4504 | 13년 전 | 483 | ||
| 4503 | 13년 전 | 526 | ||
| 4502 |
|
13년 전 | 1814 | |
| 4501 | 13년 전 | 1646 | ||
| 4500 |
|
13년 전 | 516 | |
| 4499 | 13년 전 | 1898 | ||
| 4498 | 13년 전 | 1161 | ||
| 4497 |
미션임파썩을
|
13년 전 | 894 | |
| 4496 | 13년 전 | 947 | ||
| 4495 |
공포의니이킥
|
13년 전 | 1115 | |
| 4494 | 13년 전 | 1979 | ||
| 4493 | 13년 전 | 1063 | ||
| 4492 | 13년 전 | 489 | ||
| 4491 |
두근두근따봉
|
13년 전 | 927 | |
| 4490 | 13년 전 | 1368 | ||
| 4489 |
jaein8060
|
13년 전 | 619 | |
| 4488 | 13년 전 | 1047 | ||
| 4487 |
ReeJang
|
13년 전 | 1824 | |
| 4486 | 13년 전 | 990 | ||
| 4485 | 13년 전 | 811 | ||
| 4484 | 13년 전 | 858 | ||
| 4483 | 13년 전 | 524 | ||
| 4482 | 13년 전 | 1183 | ||
| 4481 | 13년 전 | 1052 | ||
| 4480 |
|
13년 전 | 526 | |
| 4479 | 13년 전 | 918 | ||
| 4478 | 13년 전 | 3970 | ||
| 4477 | 13년 전 | 992 | ||
| 4476 |
wangko
|
13년 전 | 2711 | |
| 4475 | 13년 전 | 933 | ||
| 4474 | 13년 전 | 961 | ||
| 4473 | 13년 전 | 766 | ||
| 4472 |
|
13년 전 | 561 | |
| 4471 | 13년 전 | 1568 | ||
| 4470 | 13년 전 | 574 | ||
| 4469 | 13년 전 | 530 | ||
| 4468 | 13년 전 | 864 | ||
| 4467 | 13년 전 | 660 | ||
| 4466 | 13년 전 | 924 | ||
| 4465 | 13년 전 | 672 | ||
| 4464 | 13년 전 | 1730 | ||
| 4463 |
chongho
|
13년 전 | 2187 | |
| 4462 |
chongho
|
13년 전 | 1032 | |
| 4461 |
chongho
|
13년 전 | 1031 | |
| 4460 | 13년 전 | 757 | ||
| 4459 | 13년 전 | 2784 | ||
| 4458 | 13년 전 | 790 | ||
| 4457 | 13년 전 | 507 | ||
| 4456 | 13년 전 | 1342 | ||
| 4455 | 13년 전 | 1746 | ||
| 4454 | 13년 전 | 723 | ||
| 4453 | 13년 전 | 1260 | ||
| 4452 |
aequum
|
13년 전 | 1273 | |
| 4451 | 13년 전 | 1340 | ||
| 4450 |
도토리과자
|
13년 전 | 1438 | |
| 4449 | 13년 전 | 1093 | ||
| 4448 | 13년 전 | 8626 | ||
| 4447 | 13년 전 | 1212 | ||
| 4446 | 13년 전 | 1493 | ||
| 4445 | 13년 전 | 648 | ||
| 4444 |
|
13년 전 | 614 | |
| 4443 | 13년 전 | 702 | ||
| 4442 |
Msoft
|
13년 전 | 1064 | |
| 4441 |
|
13년 전 | 2111 | |
| 4440 | 13년 전 | 619 | ||
| 4439 | 13년 전 | 1657 | ||
| 4438 |
aequum
|
13년 전 | 1847 | |
| 4437 | 13년 전 | 997 | ||
| 4436 | 13년 전 | 925 | ||
| 4435 |
디귿소프트
|
13년 전 | 523 | |
| 4434 | 13년 전 | 1075 | ||
| 4433 | 13년 전 | 997 | ||
| 4432 | 13년 전 | 861 | ||
| 4431 | 13년 전 | 760 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기