<?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년 전
중복되는 카운트가 존재할 여지는 있겠네요
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6330 |
|
12년 전 | 1790 | |
| 6329 |
내가짱니네가짱
|
12년 전 | 1225 | |
| 6328 |
AMDbest
|
12년 전 | 487 | |
| 6327 | 12년 전 | 1692 | ||
| 6326 | 12년 전 | 1327 | ||
| 6325 | 12년 전 | 7611 | ||
| 6324 |
AMDbest
|
12년 전 | 2193 | |
| 6323 |
|
12년 전 | 1967 | |
| 6322 | 12년 전 | 2029 | ||
| 6321 | 12년 전 | 2470 | ||
| 6320 |
senseme
|
12년 전 | 568 | |
| 6319 | 12년 전 | 3715 | ||
| 6318 | 12년 전 | 1368 | ||
| 6317 |
kiplayer
|
12년 전 | 6413 | |
| 6316 | 12년 전 | 1008 | ||
| 6315 | 12년 전 | 962 | ||
| 6314 |
상엽나르도
|
12년 전 | 1278 | |
| 6313 |
검은고양이1983
|
12년 전 | 650 | |
| 6312 | 12년 전 | 3114 | ||
| 6311 | 12년 전 | 1412 | ||
| 6310 |
testers
|
12년 전 | 1480 | |
| 6309 | 12년 전 | 983 | ||
| 6308 | 12년 전 | 2598 | ||
| 6307 | 12년 전 | 1640 | ||
| 6306 | 12년 전 | 431 | ||
| 6305 | 12년 전 | 3495 | ||
| 6304 | 12년 전 | 993 | ||
| 6303 | 12년 전 | 821 | ||
| 6302 | 12년 전 | 1188 | ||
| 6301 | 12년 전 | 5561 | ||
| 6300 |
|
12년 전 | 1193 | |
| 6299 |
AMDbest
|
12년 전 | 2801 | |
| 6298 |
AMDbest
|
12년 전 | 2245 | |
| 6297 |
프리랜서개발자
|
12년 전 | 468 | |
| 6296 | 12년 전 | 2927 | ||
| 6295 |
SUPERMANs
|
12년 전 | 1375 | |
| 6294 | 12년 전 | 1290 | ||
| 6293 | 12년 전 | 1342 | ||
| 6292 |
오늘도망했다
|
12년 전 | 3264 | |
| 6291 |
senseme
|
12년 전 | 2025 | |
| 6290 |
senseme
|
12년 전 | 3683 | |
| 6289 |
senseme
|
12년 전 | 8574 | |
| 6288 |
senseme
|
12년 전 | 4166 | |
| 6287 |
senseme
|
12년 전 | 3730 | |
| 6286 |
senseme
|
12년 전 | 1355 | |
| 6285 |
senseme
|
12년 전 | 1426 | |
| 6284 |
프로프리랜서
|
12년 전 | 3149 | |
| 6283 |
프로프리랜서
|
12년 전 | 3986 | |
| 6282 |
프로프리랜서
|
12년 전 | 4388 | |
| 6281 |
프로프리랜서
|
12년 전 | 1601 | |
| 6280 | 12년 전 | 1284 | ||
| 6279 |
AMDbest
|
12년 전 | 872 | |
| 6278 | 12년 전 | 972 | ||
| 6277 |
senseme
|
12년 전 | 2713 | |
| 6276 |
senseme
|
12년 전 | 2728 | |
| 6275 |
senseme
|
12년 전 | 1251 | |
| 6274 |
|
12년 전 | 2791 | |
| 6273 | 12년 전 | 1269 | ||
| 6272 | 12년 전 | 8455 | ||
| 6271 |
senseme
|
12년 전 | 1503 | |
| 6270 |
senseme
|
12년 전 | 3762 | |
| 6269 |
senseme
|
12년 전 | 6377 | |
| 6268 |
senseme
|
12년 전 | 1557 | |
| 6267 | 12년 전 | 2833 | ||
| 6266 | 12년 전 | 577 | ||
| 6265 | 12년 전 | 1299 | ||
| 6264 | 12년 전 | 1151 | ||
| 6263 |
senseme
|
12년 전 | 1312 | |
| 6262 |
senseme
|
12년 전 | 3306 | |
| 6261 |
senseme
|
12년 전 | 1083 | |
| 6260 |
senseme
|
12년 전 | 1819 | |
| 6259 |
senseme
|
12년 전 | 1251 | |
| 6258 |
senseme
|
12년 전 | 915 | |
| 6257 | 12년 전 | 1405 | ||
| 6256 | 12년 전 | 2097 | ||
| 6255 |
senseme
|
12년 전 | 1377 | |
| 6254 |
senseme
|
12년 전 | 1262 | |
| 6253 |
senseme
|
12년 전 | 1782 | |
| 6252 |
kiplayer
|
12년 전 | 14770 | |
| 6251 | 12년 전 | 1063 | ||
| 6250 | 12년 전 | 864 | ||
| 6249 | 12년 전 | 2718 | ||
| 6248 |
senseme
|
12년 전 | 8954 | |
| 6247 | 12년 전 | 1281 | ||
| 6246 |
프로프리랜서
|
12년 전 | 1164 | |
| 6245 |
프로프리랜서
|
12년 전 | 1624 | |
| 6244 |
프로프리랜서
|
12년 전 | 1126 | |
| 6243 |
프로프리랜서
|
12년 전 | 1258 | |
| 6242 |
프로프리랜서
|
12년 전 | 3544 | |
| 6241 |
프로프리랜서
|
12년 전 | 1451 | |
| 6240 |
프로프리랜서
|
12년 전 | 2121 | |
| 6239 |
softhead
|
12년 전 | 1141 | |
| 6238 |
senseme
|
12년 전 | 1308 | |
| 6237 |
senseme
|
12년 전 | 3021 | |
| 6236 | 12년 전 | 866 | ||
| 6235 | 12년 전 | 1331 | ||
| 6234 | 12년 전 | 1602 | ||
| 6233 | 12년 전 | 2027 | ||
| 6232 | 12년 전 | 2135 | ||
| 6231 | 12년 전 | 2559 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기