아래 댓글에 올린것은 제가 착각한 부분이 있어서 다시 올립니다.
백만건 테스트 거쳣으며 중복 발생하지 않습니다.
//지정된 자릿수의 랜덤한 숫자를 반환합니다. 최대 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년 전
고맙습니다. 아침부터 힘이 나네요
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 8230 | 9년 전 | 189 | ||
| 8229 | 9년 전 | 169 | ||
| 8228 |
커네드커네드
|
9년 전 | 208 | |
| 8227 | 9년 전 | 248 | ||
| 8226 | 9년 전 | 269 | ||
| 8225 | 9년 전 | 248 | ||
| 8224 | 9년 전 | 254 | ||
| 8223 | 9년 전 | 230 | ||
| 8222 |
|
9년 전 | 294 | |
| 8221 | 9년 전 | 193 | ||
| 8220 | 9년 전 | 235 | ||
| 8219 | 9년 전 | 207 | ||
| 8218 | 9년 전 | 253 | ||
| 8217 |
star3840
|
9년 전 | 215 | |
| 8216 | 9년 전 | 287 | ||
| 8215 | 9년 전 | 228 | ||
| 8214 | 9년 전 | 335 | ||
| 8213 | 9년 전 | 295 | ||
| 8212 | 9년 전 | 209 | ||
| 8211 | 9년 전 | 379 | ||
| 8210 | 9년 전 | 371 | ||
| 8209 | 9년 전 | 453 | ||
| 8208 | 9년 전 | 341 | ||
| 8207 | 9년 전 | 350 | ||
| 8206 |
|
9년 전 | 296 | |
| 8205 | 9년 전 | 271 | ||
| 8204 | 9년 전 | 257 | ||
| 8203 | 9년 전 | 338 | ||
| 8202 | 9년 전 | 250 | ||
| 8201 | 9년 전 | 290 | ||
| 8200 | 9년 전 | 294 | ||
| 8199 | 9년 전 | 317 | ||
| 8198 | 9년 전 | 281 | ||
| 8197 | 9년 전 | 264 | ||
| 8196 | 9년 전 | 689 | ||
| 8195 | 9년 전 | 273 | ||
| 8194 | 9년 전 | 388 | ||
| 8193 | 9년 전 | 303 | ||
| 8192 | 9년 전 | 309 | ||
| 8191 | 9년 전 | 267 | ||
| 8190 | 9년 전 | 250 | ||
| 8189 | 9년 전 | 309 | ||
| 8188 | 9년 전 | 241 | ||
| 8187 | 9년 전 | 260 | ||
| 8186 | 9년 전 | 255 | ||
| 8185 | 9년 전 | 424 | ||
| 8184 | 9년 전 | 212 | ||
| 8183 | 9년 전 | 420 | ||
| 8182 | 9년 전 | 288 | ||
| 8181 | 9년 전 | 245 | ||
| 8180 | 9년 전 | 821 | ||
| 8179 | 9년 전 | 594 | ||
| 8178 | 9년 전 | 452 | ||
| 8177 |
kiplayer
|
9년 전 | 450 | |
| 8176 | 9년 전 | 481 | ||
| 8175 | 9년 전 | 366 | ||
| 8174 | 9년 전 | 359 | ||
| 8173 | 9년 전 | 451 | ||
| 8172 | 9년 전 | 331 | ||
| 8171 | 9년 전 | 294 | ||
| 8170 | 9년 전 | 409 | ||
| 8169 |
커네드커네드
|
9년 전 | 363 | |
| 8168 | 9년 전 | 447 | ||
| 8167 | 9년 전 | 439 | ||
| 8166 | 9년 전 | 338 | ||
| 8165 | 9년 전 | 275 | ||
| 8164 | 9년 전 | 411 | ||
| 8163 | 9년 전 | 415 | ||
| 8162 | 9년 전 | 398 | ||
| 8161 | 9년 전 | 413 | ||
| 8160 |
|
9년 전 | 634 | |
| 8159 | 9년 전 | 579 | ||
| 8158 | 9년 전 | 372 | ||
| 8157 | 9년 전 | 492 | ||
| 8156 | 9년 전 | 363 | ||
| 8155 | 9년 전 | 376 | ||
| 8154 |
00년생용띠
|
9년 전 | 704 | |
| 8153 | 9년 전 | 343 | ||
| 8152 |
|
9년 전 | 520 | |
| 8151 | 9년 전 | 511 | ||
| 8150 | 9년 전 | 630 | ||
| 8149 |
Jangfolk
|
9년 전 | 487 | |
| 8148 | 9년 전 | 303 | ||
| 8147 | 9년 전 | 487 | ||
| 8146 | 9년 전 | 568 | ||
| 8145 | 9년 전 | 523 | ||
| 8144 | 9년 전 | 493 | ||
| 8143 | 9년 전 | 318 | ||
| 8142 | 9년 전 | 538 | ||
| 8141 | 9년 전 | 484 | ||
| 8140 | 9년 전 | 1053 | ||
| 8139 | 9년 전 | 388 | ||
| 8138 |
전갈자리남자
|
9년 전 | 494 | |
| 8137 | 9년 전 | 532 | ||
| 8136 | 9년 전 | 863 | ||
| 8135 |
|
9년 전 | 905 | |
| 8134 |
PlayPixel
|
9년 전 | 646 | |
| 8133 |
|
9년 전 | 551 | |
| 8132 | 9년 전 | 588 | ||
| 8131 | 9년 전 | 943 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기