아래 댓글에 올린것은 제가 착각한 부분이 있어서 다시 올립니다.
백만건 테스트 거쳣으며 중복 발생하지 않습니다.
//지정된 자릿수의 랜덤한 숫자를 반환합니다. 최대 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년 전
고맙습니다. 아침부터 힘이 나네요
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 5030 | 13년 전 | 784 | ||
| 5029 | 13년 전 | 465 | ||
| 5028 | 13년 전 | 728 | ||
| 5027 | 13년 전 | 1317 | ||
| 5026 | 13년 전 | 548 | ||
| 5025 | 13년 전 | 1369 | ||
| 5024 | 13년 전 | 422 | ||
| 5023 | 13년 전 | 662 | ||
| 5022 | 13년 전 | 425 | ||
| 5021 | 13년 전 | 665 | ||
| 5020 | 13년 전 | 515 | ||
| 5019 | 13년 전 | 857 | ||
| 5018 | 13년 전 | 906 | ||
| 5017 | 13년 전 | 781 | ||
| 5016 | 13년 전 | 2625 | ||
| 5015 | 13년 전 | 413 | ||
| 5014 | 13년 전 | 672 | ||
| 5013 | 13년 전 | 587 | ||
| 5012 |
JacobJeon
|
13년 전 | 1073 | |
| 5011 | 13년 전 | 806 | ||
| 5010 | 13년 전 | 1442 | ||
| 5009 |
JacobJeon
|
13년 전 | 1801 | |
| 5008 | 13년 전 | 1151 | ||
| 5007 | 13년 전 | 3012 | ||
| 5006 |
|
13년 전 | 1307 | |
| 5005 | 13년 전 | 698 | ||
| 5004 | 13년 전 | 2105 | ||
| 5003 | 13년 전 | 2529 | ||
| 5002 | 13년 전 | 384 | ||
| 5001 | 13년 전 | 519 | ||
| 5000 | 13년 전 | 427 | ||
| 4999 | 13년 전 | 526 | ||
| 4998 | 13년 전 | 473 | ||
| 4997 | 13년 전 | 661 | ||
| 4996 | 13년 전 | 1919 | ||
| 4995 | 13년 전 | 393 | ||
| 4994 | 13년 전 | 382 | ||
| 4993 | 13년 전 | 528 | ||
| 4992 | 13년 전 | 503 | ||
| 4991 | 13년 전 | 388 | ||
| 4990 | 13년 전 | 710 | ||
| 4989 | 13년 전 | 653 | ||
| 4988 | 13년 전 | 400 | ||
| 4987 | 13년 전 | 422 | ||
| 4986 | 13년 전 | 1380 | ||
| 4985 | 13년 전 | 664 | ||
| 4984 | 13년 전 | 1046 | ||
| 4983 | 13년 전 | 413 | ||
| 4982 |
쥬드125
|
13년 전 | 1018 | |
| 4981 | 13년 전 | 548 | ||
| 4980 | 13년 전 | 418 | ||
| 4979 | 13년 전 | 694 | ||
| 4978 | 13년 전 | 2180 | ||
| 4977 |
atria
|
13년 전 | 864 | |
| 4976 | 13년 전 | 1531 | ||
| 4975 | 13년 전 | 439 | ||
| 4974 | 13년 전 | 467 | ||
| 4973 | 13년 전 | 703 | ||
| 4972 | 13년 전 | 461 | ||
| 4971 | 13년 전 | 1392 | ||
| 4970 | 13년 전 | 370 | ||
| 4969 | 13년 전 | 423 | ||
| 4968 | 13년 전 | 732 | ||
| 4967 | 13년 전 | 533 | ||
| 4966 | 13년 전 | 445 | ||
| 4965 | 13년 전 | 587 | ||
| 4964 | 13년 전 | 590 | ||
| 4963 | 13년 전 | 427 | ||
| 4962 | 13년 전 | 2250 | ||
| 4961 | 13년 전 | 1350 | ||
| 4960 | 13년 전 | 1231 | ||
| 4959 | 13년 전 | 427 | ||
| 4958 | 13년 전 | 382 | ||
| 4957 | 13년 전 | 472 | ||
| 4956 | 13년 전 | 702 | ||
| 4955 | 13년 전 | 494 | ||
| 4954 | 13년 전 | 1064 | ||
| 4953 | 13년 전 | 1158 | ||
| 4952 | 13년 전 | 750 | ||
| 4951 |
sjsmsrjfflauswnrsmse
|
13년 전 | 879 | |
| 4950 | 13년 전 | 1910 | ||
| 4949 | 13년 전 | 2220 | ||
| 4948 | 13년 전 | 5528 | ||
| 4947 | 13년 전 | 413 | ||
| 4946 | 13년 전 | 851 | ||
| 4945 | 13년 전 | 406 | ||
| 4944 | 13년 전 | 608 | ||
| 4943 |
마당쇠2000
|
13년 전 | 1256 | |
| 4942 |
cula100jak
|
13년 전 | 828 | |
| 4941 | 13년 전 | 474 | ||
| 4940 | 13년 전 | 573 | ||
| 4939 | 13년 전 | 417 | ||
| 4938 | 13년 전 | 567 | ||
| 4937 | 13년 전 | 1499 | ||
| 4936 |
techer
|
13년 전 | 1852 | |
| 4935 | 13년 전 | 724 | ||
| 4934 | 13년 전 | 959 | ||
| 4933 | 13년 전 | 2048 | ||
| 4932 |
kajama78
|
13년 전 | 963 | |
| 4931 | 13년 전 | 984 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기