<?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년 전
중복되는 카운트가 존재할 여지는 있겠네요
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6430 | 12년 전 | 977 | ||
| 6429 | 12년 전 | 9100 | ||
| 6428 | 12년 전 | 599 | ||
| 6427 |
제이티37
|
12년 전 | 1568 | |
| 6426 |
프로프리랜서
|
12년 전 | 1154 | |
| 6425 |
프로프리랜서
|
12년 전 | 1608 | |
| 6424 |
프로프리랜서
|
12년 전 | 1807 | |
| 6423 | 12년 전 | 1000 | ||
| 6422 |
퍼블리셔지노군
|
12년 전 | 1571 | |
| 6421 | 12년 전 | 2207 | ||
| 6420 |
|
12년 전 | 1334 | |
| 6419 |
|
12년 전 | 1287 | |
| 6418 | 12년 전 | 1181 | ||
| 6417 |
senseme
|
12년 전 | 7418 | |
| 6416 |
senseme
|
12년 전 | 1327 | |
| 6415 |
senseme
|
12년 전 | 1190 | |
| 6414 |
senseme
|
12년 전 | 1967 | |
| 6413 |
senseme
|
12년 전 | 971 | |
| 6412 |
senseme
|
12년 전 | 1489 | |
| 6411 |
senseme
|
12년 전 | 1095 | |
| 6410 |
senseme
|
12년 전 | 1045 | |
| 6409 |
PASKRAN
|
12년 전 | 2818 | |
| 6408 | 12년 전 | 10796 | ||
| 6407 | 12년 전 | 2989 | ||
| 6406 |
프로프리랜서
|
12년 전 | 2828 | |
| 6405 |
프로프리랜서
|
12년 전 | 1369 | |
| 6404 |
프로프리랜서
|
12년 전 | 2723 | |
| 6403 |
프로프리랜서
|
12년 전 | 817 | |
| 6402 |
프로프리랜서
|
12년 전 | 1728 | |
| 6401 |
프로프리랜서
|
12년 전 | 1139 | |
| 6400 |
프로프리랜서
|
12년 전 | 1464 | |
| 6399 |
프로프리랜서
|
12년 전 | 1179 | |
| 6398 |
프로프리랜서
|
12년 전 | 1486 | |
| 6397 |
프로프리랜서
|
12년 전 | 3602 | |
| 6396 | 12년 전 | 1869 | ||
| 6395 | 12년 전 | 920 | ||
| 6394 |
|
12년 전 | 5239 | |
| 6393 |
제이티37
|
12년 전 | 1202 | |
| 6392 |
songsinica
|
12년 전 | 1204 | |
| 6391 |
|
12년 전 | 3380 | |
| 6390 |
|
12년 전 | 1623 | |
| 6389 | 12년 전 | 4855 | ||
| 6388 |
스누피사랑
|
12년 전 | 5431 | |
| 6387 | 12년 전 | 1838 | ||
| 6386 | 12년 전 | 3059 | ||
| 6385 |
희망과열정
|
12년 전 | 923 | |
| 6384 | 12년 전 | 3287 | ||
| 6383 | 12년 전 | 10595 | ||
| 6382 |
|
12년 전 | 5790 | |
| 6381 |
SugarSkull
|
12년 전 | 1030 | |
| 6380 | 12년 전 | 777 | ||
| 6379 |
|
12년 전 | 1982 | |
| 6378 | 12년 전 | 1562 | ||
| 6377 | 12년 전 | 497 | ||
| 6376 |
후라보노보노
|
12년 전 | 1332 | |
| 6375 | 12년 전 | 2866 | ||
| 6374 | 12년 전 | 832 | ||
| 6373 | 12년 전 | 2367 | ||
| 6372 |
takumi22
|
12년 전 | 1238 | |
| 6371 |
개초보제이
|
12년 전 | 772 | |
| 6370 |
고급자가되고
|
12년 전 | 1461 | |
| 6369 | 12년 전 | 881 | ||
| 6368 | 12년 전 | 3178 | ||
| 6367 | 12년 전 | 1879 | ||
| 6366 | 12년 전 | 2876 | ||
| 6365 |
lilyosia
|
12년 전 | 1794 | |
| 6364 | 12년 전 | 1057 | ||
| 6363 | 12년 전 | 1588 | ||
| 6362 | 12년 전 | 2733 | ||
| 6361 | 12년 전 | 2556 | ||
| 6360 | 12년 전 | 1001 | ||
| 6359 | 12년 전 | 2104 | ||
| 6358 |
|
12년 전 | 1787 | |
| 6357 |
에헤라디야자진방아를돌려라
|
12년 전 | 778 | |
| 6356 | 12년 전 | 2084 | ||
| 6355 | 12년 전 | 3787 | ||
| 6354 | 12년 전 | 3101 | ||
| 6353 | 12년 전 | 1546 | ||
| 6352 | 12년 전 | 7769 | ||
| 6351 | 12년 전 | 2537 | ||
| 6350 | 12년 전 | 2798 | ||
| 6349 | 12년 전 | 1880 | ||
| 6348 | 12년 전 | 3546 | ||
| 6347 | 12년 전 | 1446 | ||
| 6346 | 12년 전 | 1183 | ||
| 6345 | 12년 전 | 1835 | ||
| 6344 | 12년 전 | 1409 | ||
| 6343 |
프로프리랜서
|
12년 전 | 2059 | |
| 6342 |
프로프리랜서
|
12년 전 | 1381 | |
| 6341 |
프로프리랜서
|
12년 전 | 1812 | |
| 6340 |
프로프리랜서
|
12년 전 | 1897 | |
| 6339 |
프로프리랜서
|
12년 전 | 1338 | |
| 6338 |
프로프리랜서
|
12년 전 | 1591 | |
| 6337 | 12년 전 | 5267 | ||
| 6336 |
프로프리랜서
|
12년 전 | 1629 | |
| 6335 |
프로프리랜서
|
12년 전 | 951 | |
| 6334 |
프로프리랜서
|
12년 전 | 1328 | |
| 6333 |
프로프리랜서
|
12년 전 | 2438 | |
| 6332 | 12년 전 | 1102 | ||
| 6331 |
돗단배123
|
12년 전 | 1421 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기