<?php
//지정된 자릿수의 랜덤한 숫자를 반환합니다. 최대 10까지 가능합니다. 4 이면 1000 에서 9999 사이의 랜덤 숫자
function get_rand_number($len=4) {
$len = abs((int)$len);
if ($len < 1) $len = 1;
else if ($len > 10) $len = 10;
return rand(pow(10, $len - 1), (pow(10, $len) - 1));
}
//넘어온 세자리수를 36진수로 변환해서 반환합니다. preg_match_callback 을 통해서만 사용됩니다.
function get_simple_36($m){
$str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$div = floor($m[0] / 36);
$rest = $m[0] % 36;
return $str[$div] . $str[$rest];
}
//지정된 자리수에 존재하는 소수 전체를 배열로 반환합니다. max len = 5
function get_simple_prime_number($len=5){
$len = abs((int)$len);
if ($len < 1) $len = 1;
else if ($len > 5) $len = 5;
$prime_1 = Array(1, 2, 3, 5, 7);
if ($len == 1) return $prime_1;
$start = pow(10, ($len - 1)) + 1;//101
$end = pow(10, $len) - 1;//999
$prime = $prime_1;
unset($prime[0]);//1제거
unset($prime[1]);//2제거
$array = Array();
for($i = 11; $i <= $end; $i+=2){//10보다 큰 소수에는 짝수가 없다.
$max = floor(sqrt($i));
foreach($prime as $j) {
if ($j > $max) break;
if ($i % $j == 0) continue 2;
}
$prime[] = $i;
if ($i >= $start) $array[] = $i;
}
return $array;
}
//지정된 자릿수의 숫자로된 시리얼을 반환합니다. - 를 포함하고 싶지 않을때는 $cut 이 $len 보다 크거나 같으면 됩니다. max len = 36
function get_serial($len=16, $cut=4, $hipen='-'){
$len = abs((int)$len);
if ($len < 1) $len = 16;
else if ($len > 36) $len = 36;
$cut = abs((int)$cut);
if ($cut < 1) $cut = 4;
else if ($cut > $len) $cut = $len;
list($usec, $sec) = explode(' ', microtime());
$base_number = (string)$sec . str_replace('0.', '', (string)$usec);
$base_number .= (string)get_rand_number(10) . (string)get_rand_number(8);//36자리 유니크한 숫자 문자열
$prime = get_simple_prime_number(5);//5자리 소수 배열
shuffle($prime);
$prime = $prime[0];//랜덤한 5자리 소수
$serial = bcmul(substr($base_number, 0, $len), $prime);
$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("`(.{" . $cut . "})`", "$1" . $hipen, $serial, floor(($len-1) / $cut));
}
//지정된 자릿수의 숫자와 영문으로된 시리얼을 반환합니다. - 를 포함하고 싶지 않을때는 $cut 이 $len 보다 크거나 같으면 됩니다. max len = 24
function get_serial_mix($len=16, $cut=4, $hipen='-'){
$len = abs((int)$len);
if ($len < 1) $len = 16;
else if ($len > 24) $len = 24;
$cut = abs((int)$cut);
if ($cut < 1) $cut = 4;
else if ($cut > $len) $cut = $len;
$len2 = (int)($len * 3 / 2);
if ($len2 % 2 == 1) $len2 += 1;
$serial = get_serial($len2, $len2, $hipen);
$serial = substr(preg_replace_callback("`.{3}`", "get_simple_36", $serial), 0, $len);
return preg_replace("`(.{" . $cut . "})`", "$1" . $hipen, $serial, floor(($len-1) / $cut));
}
echo get_serial_mix(16, 4, '-');
?>
//지정된 자릿수의 랜덤한 숫자를 반환합니다. 최대 10까지 가능합니다. 4 이면 1000 에서 9999 사이의 랜덤 숫자
function get_rand_number($len=4) {
$len = abs((int)$len);
if ($len < 1) $len = 1;
else if ($len > 10) $len = 10;
return rand(pow(10, $len - 1), (pow(10, $len) - 1));
}
//넘어온 세자리수를 36진수로 변환해서 반환합니다. preg_match_callback 을 통해서만 사용됩니다.
function get_simple_36($m){
$str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$div = floor($m[0] / 36);
$rest = $m[0] % 36;
return $str[$div] . $str[$rest];
}
//지정된 자리수에 존재하는 소수 전체를 배열로 반환합니다. max len = 5
function get_simple_prime_number($len=5){
$len = abs((int)$len);
if ($len < 1) $len = 1;
else if ($len > 5) $len = 5;
$prime_1 = Array(1, 2, 3, 5, 7);
if ($len == 1) return $prime_1;
$start = pow(10, ($len - 1)) + 1;//101
$end = pow(10, $len) - 1;//999
$prime = $prime_1;
unset($prime[0]);//1제거
unset($prime[1]);//2제거
$array = Array();
for($i = 11; $i <= $end; $i+=2){//10보다 큰 소수에는 짝수가 없다.
$max = floor(sqrt($i));
foreach($prime as $j) {
if ($j > $max) break;
if ($i % $j == 0) continue 2;
}
$prime[] = $i;
if ($i >= $start) $array[] = $i;
}
return $array;
}
//지정된 자릿수의 숫자로된 시리얼을 반환합니다. - 를 포함하고 싶지 않을때는 $cut 이 $len 보다 크거나 같으면 됩니다. max len = 36
function get_serial($len=16, $cut=4, $hipen='-'){
$len = abs((int)$len);
if ($len < 1) $len = 16;
else if ($len > 36) $len = 36;
$cut = abs((int)$cut);
if ($cut < 1) $cut = 4;
else if ($cut > $len) $cut = $len;
list($usec, $sec) = explode(' ', microtime());
$base_number = (string)$sec . str_replace('0.', '', (string)$usec);
$base_number .= (string)get_rand_number(10) . (string)get_rand_number(8);//36자리 유니크한 숫자 문자열
$prime = get_simple_prime_number(5);//5자리 소수 배열
shuffle($prime);
$prime = $prime[0];//랜덤한 5자리 소수
$serial = bcmul(substr($base_number, 0, $len), $prime);
$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("`(.{" . $cut . "})`", "$1" . $hipen, $serial, floor(($len-1) / $cut));
}
//지정된 자릿수의 숫자와 영문으로된 시리얼을 반환합니다. - 를 포함하고 싶지 않을때는 $cut 이 $len 보다 크거나 같으면 됩니다. max len = 24
function get_serial_mix($len=16, $cut=4, $hipen='-'){
$len = abs((int)$len);
if ($len < 1) $len = 16;
else if ($len > 24) $len = 24;
$cut = abs((int)$cut);
if ($cut < 1) $cut = 4;
else if ($cut > $len) $cut = $len;
$len2 = (int)($len * 3 / 2);
if ($len2 % 2 == 1) $len2 += 1;
$serial = get_serial($len2, $len2, $hipen);
$serial = substr(preg_replace_callback("`.{3}`", "get_simple_36", $serial), 0, $len);
return preg_replace("`(.{" . $cut . "})`", "$1" . $hipen, $serial, floor(($len-1) / $cut));
}
echo get_serial_mix(16, 4, '-');
?>
댓글 1개
가오가이거
12년 전
중복되는 카운트가 존재할 여지는 있겠네요
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6630 |
차가운바람
|
12년 전 | 1160 | |
| 6629 | 12년 전 | 1155 | ||
| 6628 |
put777
|
12년 전 | 642 | |
| 6627 |
|
12년 전 | 696 | |
| 6626 | 12년 전 | 1616 | ||
| 6625 |
|
12년 전 | 718 | |
| 6624 |
미켈란젤로의왼손
|
12년 전 | 481 | |
| 6623 |
|
12년 전 | 1043 | |
| 6622 | 12년 전 | 1385 | ||
| 6621 |
차가운바람
|
12년 전 | 631 | |
| 6620 | 12년 전 | 731 | ||
| 6619 |
|
12년 전 | 968 | |
| 6618 | 12년 전 | 1741 | ||
| 6617 | 12년 전 | 638 | ||
| 6616 |
차가운바람
|
12년 전 | 893 | |
| 6615 | 12년 전 | 2853 | ||
| 6614 | 12년 전 | 613 | ||
| 6613 |
강명구베드로
|
12년 전 | 529 | |
| 6612 |
|
12년 전 | 424 | |
| 6611 | 12년 전 | 1205 | ||
| 6610 | 12년 전 | 1021 | ||
| 6609 | 12년 전 | 3679 | ||
| 6608 |
|
12년 전 | 830 | |
| 6607 | 12년 전 | 692 | ||
| 6606 | 12년 전 | 565 | ||
| 6605 | 12년 전 | 453 | ||
| 6604 | 12년 전 | 972 | ||
| 6603 |
geektoo
|
12년 전 | 695 | |
| 6602 | 12년 전 | 836 | ||
| 6601 | 12년 전 | 359 | ||
| 6600 | 12년 전 | 401 | ||
| 6599 | 12년 전 | 540 | ||
| 6598 | 12년 전 | 936 | ||
| 6597 | 12년 전 | 933 | ||
| 6596 | 12년 전 | 416 | ||
| 6595 | 12년 전 | 787 | ||
| 6594 | 12년 전 | 4576 | ||
| 6593 | 12년 전 | 2579 | ||
| 6592 | 12년 전 | 826 | ||
| 6591 | 12년 전 | 584 | ||
| 6590 |
|
12년 전 | 1389 | |
| 6589 | 12년 전 | 760 | ||
| 6588 |
GINUSSOFT
|
12년 전 | 5125 | |
| 6587 | 12년 전 | 6213 | ||
| 6586 | 12년 전 | 1045 | ||
| 6585 | 12년 전 | 803 | ||
| 6584 | 12년 전 | 459 | ||
| 6583 |
|
12년 전 | 983 | |
| 6582 | 12년 전 | 871 | ||
| 6581 | 12년 전 | 841 | ||
| 6580 | 12년 전 | 617 | ||
| 6579 |
알랑가몰라
|
12년 전 | 921 | |
| 6578 | 12년 전 | 1328 | ||
| 6577 | 12년 전 | 1500 | ||
| 6576 |
경dragon
|
12년 전 | 769 | |
| 6575 | 12년 전 | 1880 | ||
| 6574 | 12년 전 | 681 | ||
| 6573 | 12년 전 | 978 | ||
| 6572 |
|
12년 전 | 1664 | |
| 6571 |
CTOMAN
|
12년 전 | 1954 | |
| 6570 | 12년 전 | 1729 | ||
| 6569 | 12년 전 | 1885 | ||
| 6568 | 12년 전 | 2403 | ||
| 6567 | 12년 전 | 1031 | ||
| 6566 |
lainfox
|
12년 전 | 1529 | |
| 6565 | 12년 전 | 3655 | ||
| 6564 |
제주프라이스
|
12년 전 | 1533 | |
| 6563 | 12년 전 | 1574 | ||
| 6562 |
프로프리랜서
|
12년 전 | 1345 | |
| 6561 |
프로프리랜서
|
12년 전 | 964 | |
| 6560 |
프로프리랜서
|
12년 전 | 1218 | |
| 6559 |
프로프리랜서
|
12년 전 | 1136 | |
| 6558 |
프로프리랜서
|
12년 전 | 1353 | |
| 6557 |
프로프리랜서
|
12년 전 | 1978 | |
| 6556 |
프로프리랜서
|
12년 전 | 1524 | |
| 6555 |
프로프리랜서
|
12년 전 | 1366 | |
| 6554 |
프로프리랜서
|
12년 전 | 3890 | |
| 6553 |
프로프리랜서
|
12년 전 | 1509 | |
| 6552 | 12년 전 | 844 | ||
| 6551 |
왕초보sasa
|
12년 전 | 1534 | |
| 6550 |
왕초보sasa
|
12년 전 | 628 | |
| 6549 |
왕초보sasa
|
12년 전 | 903 | |
| 6548 | 12년 전 | 1301 | ||
| 6547 | 12년 전 | 1191 | ||
| 6546 | 12년 전 | 5156 | ||
| 6545 | 12년 전 | 2514 | ||
| 6544 |
AnnieK
|
12년 전 | 1777 | |
| 6543 |
베르무트7
|
12년 전 | 627 | |
| 6542 |
오늘도망했다
|
12년 전 | 2232 | |
| 6541 | 12년 전 | 819 | ||
| 6540 | 12년 전 | 1135 | ||
| 6539 | 12년 전 | 849 | ||
| 6538 |
senseme
|
12년 전 | 3371 | |
| 6537 | 12년 전 | 779 | ||
| 6536 | 12년 전 | 3666 | ||
| 6535 | 12년 전 | 1349 | ||
| 6534 | 12년 전 | 1624 | ||
| 6533 | 12년 전 | 2242 | ||
| 6532 |
냐옹이사범
|
12년 전 | 2307 | |
| 6531 | 12년 전 | 568 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기