<?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년 전
중복되는 카운트가 존재할 여지는 있겠네요
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6130 |
gender
|
12년 전 | 1082 | |
| 6129 | 12년 전 | 1320 | ||
| 6128 |
|
12년 전 | 3459 | |
| 6127 | 12년 전 | 693 | ||
| 6126 |
|
12년 전 | 2204 | |
| 6125 |
|
12년 전 | 4880 | |
| 6124 | 12년 전 | 654 | ||
| 6123 | 12년 전 | 3837 | ||
| 6122 | 12년 전 | 1016 | ||
| 6121 | 12년 전 | 3747 | ||
| 6120 | 12년 전 | 905 | ||
| 6119 | 12년 전 | 1767 | ||
| 6118 | 12년 전 | 925 | ||
| 6117 | 12년 전 | 2147 | ||
| 6116 | 12년 전 | 7936 | ||
| 6115 | 12년 전 | 1916 | ||
| 6114 |
|
12년 전 | 1703 | |
| 6113 | 12년 전 | 1520 | ||
| 6112 | 12년 전 | 589 | ||
| 6111 | 12년 전 | 2104 | ||
| 6110 | 12년 전 | 1843 | ||
| 6109 | 12년 전 | 634 | ||
| 6108 | 12년 전 | 1196 | ||
| 6107 | 12년 전 | 615 | ||
| 6106 | 12년 전 | 900 | ||
| 6105 | 12년 전 | 1185 | ||
| 6104 | 12년 전 | 3579 | ||
| 6103 | 12년 전 | 2112 | ||
| 6102 | 12년 전 | 2305 | ||
| 6101 | 12년 전 | 3667 | ||
| 6100 | 12년 전 | 3477 | ||
| 6099 | 12년 전 | 3141 | ||
| 6098 | 12년 전 | 4020 | ||
| 6097 | 12년 전 | 1009 | ||
| 6096 | 12년 전 | 5976 | ||
| 6095 | 12년 전 | 1364 | ||
| 6094 | 12년 전 | 1217 | ||
| 6093 | 12년 전 | 3400 | ||
| 6092 | 12년 전 | 3039 | ||
| 6091 | 12년 전 | 5186 | ||
| 6090 | 12년 전 | 2697 | ||
| 6089 | 12년 전 | 3325 | ||
| 6088 | 12년 전 | 1013 | ||
| 6087 | 12년 전 | 842 | ||
| 6086 | 12년 전 | 2016 | ||
| 6085 |
|
12년 전 | 806 | |
| 6084 |
웹디자인되고파
|
12년 전 | 2213 | |
| 6083 | 12년 전 | 1504 | ||
| 6082 | 12년 전 | 1105 | ||
| 6081 | 12년 전 | 2096 | ||
| 6080 |
Stiven
|
12년 전 | 2309 | |
| 6079 |
프로프리랜서
|
12년 전 | 1311 | |
| 6078 |
프로프리랜서
|
12년 전 | 785 | |
| 6077 |
프로프리랜서
|
12년 전 | 1335 | |
| 6076 |
프로프리랜서
|
12년 전 | 824 | |
| 6075 |
프로프리랜서
|
12년 전 | 1214 | |
| 6074 | 12년 전 | 3852 | ||
| 6073 | 12년 전 | 3947 | ||
| 6072 | 12년 전 | 1371 | ||
| 6071 | 12년 전 | 6981 | ||
| 6070 | 12년 전 | 7563 | ||
| 6069 | 12년 전 | 2313 | ||
| 6068 | 12년 전 | 3864 | ||
| 6067 |
smwkd
|
12년 전 | 629 | |
| 6066 | 12년 전 | 3653 | ||
| 6065 | 12년 전 | 3480 | ||
| 6064 | 12년 전 | 2713 | ||
| 6063 | 12년 전 | 2825 | ||
| 6062 | 12년 전 | 2360 | ||
| 6061 | 12년 전 | 2268 | ||
| 6060 | 12년 전 | 5171 | ||
| 6059 | 12년 전 | 2802 | ||
| 6058 | 12년 전 | 3128 | ||
| 6057 | 12년 전 | 2256 | ||
| 6056 | 12년 전 | 6836 | ||
| 6055 | 12년 전 | 2576 | ||
| 6054 | 12년 전 | 3428 | ||
| 6053 | 12년 전 | 2318 | ||
| 6052 | 12년 전 | 4816 | ||
| 6051 | 12년 전 | 3697 | ||
| 6050 | 12년 전 | 2550 | ||
| 6049 | 12년 전 | 2233 | ||
| 6048 |
|
12년 전 | 1287 | |
| 6047 | 12년 전 | 3427 | ||
| 6046 | 12년 전 | 4087 | ||
| 6045 | 12년 전 | 3453 | ||
| 6044 | 12년 전 | 5328 | ||
| 6043 | 12년 전 | 1647 | ||
| 6042 | 12년 전 | 1274 | ||
| 6041 | 12년 전 | 5162 | ||
| 6040 | 12년 전 | 936 | ||
| 6039 | 12년 전 | 3402 | ||
| 6038 | 12년 전 | 3405 | ||
| 6037 | 12년 전 | 2991 | ||
| 6036 | 12년 전 | 3340 | ||
| 6035 | 12년 전 | 2863 | ||
| 6034 | 12년 전 | 2843 | ||
| 6033 | 12년 전 | 2863 | ||
| 6032 | 12년 전 | 2854 | ||
| 6031 | 12년 전 | 2875 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기