<?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년 전
중복되는 카운트가 존재할 여지는 있겠네요
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6530 |
퍼블리셔강
|
12년 전 | 645 | |
| 6529 | 12년 전 | 1299 | ||
| 6528 | 12년 전 | 619 | ||
| 6527 | 12년 전 | 788 | ||
| 6526 | 12년 전 | 6579 | ||
| 6525 | 12년 전 | 548 | ||
| 6524 | 12년 전 | 837 | ||
| 6523 | 12년 전 | 483 | ||
| 6522 | 12년 전 | 532 | ||
| 6521 | 12년 전 | 797 | ||
| 6520 | 12년 전 | 737 | ||
| 6519 | 12년 전 | 1739 | ||
| 6518 |
가슴시린하늘
|
12년 전 | 1723 | |
| 6517 | 12년 전 | 1362 | ||
| 6516 | 12년 전 | 5225 | ||
| 6515 | 12년 전 | 1494 | ||
| 6514 | 12년 전 | 1596 | ||
| 6513 | 12년 전 | 950 | ||
| 6512 | 12년 전 | 1977 | ||
| 6511 | 12년 전 | 1367 | ||
| 6510 | 12년 전 | 3058 | ||
| 6509 |
프로프리랜서
|
12년 전 | 2547 | |
| 6508 |
프로프리랜서
|
12년 전 | 1897 | |
| 6507 |
프로프리랜서
|
12년 전 | 2373 | |
| 6506 |
프로프리랜서
|
12년 전 | 1853 | |
| 6505 |
프로프리랜서
|
12년 전 | 1631 | |
| 6504 | 12년 전 | 1023 | ||
| 6503 | 12년 전 | 1126 | ||
| 6502 |
프로프리랜서
|
12년 전 | 5554 | |
| 6501 |
프로프리랜서
|
12년 전 | 2599 | |
| 6500 |
프로프리랜서
|
12년 전 | 3082 | |
| 6499 |
프로프리랜서
|
12년 전 | 1750 | |
| 6498 |
프로프리랜서
|
12년 전 | 1461 | |
| 6497 | 12년 전 | 806 | ||
| 6496 |
yunkiri486
|
12년 전 | 1807 | |
| 6495 | 12년 전 | 917 | ||
| 6494 | 12년 전 | 1490 | ||
| 6493 | 12년 전 | 2761 | ||
| 6492 |
오늘도망했다
|
12년 전 | 2336 | |
| 6491 |
오늘도망했다
|
12년 전 | 1677 | |
| 6490 |
오늘도망했다
|
12년 전 | 6655 | |
| 6489 |
오늘도망했다
|
12년 전 | 2493 | |
| 6488 |
홈피119
|
12년 전 | 697 | |
| 6487 | 12년 전 | 665 | ||
| 6486 | 12년 전 | 1407 | ||
| 6485 | 12년 전 | 2049 | ||
| 6484 | 12년 전 | 896 | ||
| 6483 | 12년 전 | 710 | ||
| 6482 | 12년 전 | 1334 | ||
| 6481 | 12년 전 | 1464 | ||
| 6480 |
Header
|
12년 전 | 687 | |
| 6479 |
|
12년 전 | 1124 | |
| 6478 |
개초보제이
|
12년 전 | 1392 | |
| 6477 | 12년 전 | 788 | ||
| 6476 | 12년 전 | 1071 | ||
| 6475 | 12년 전 | 3670 | ||
| 6474 | 12년 전 | 1419 | ||
| 6473 | 12년 전 | 961 | ||
| 6472 | 12년 전 | 845 | ||
| 6471 |
AMDbest
|
12년 전 | 1202 | |
| 6470 |
jinmuk
|
12년 전 | 1443 | |
| 6469 |
jinmuk
|
12년 전 | 4245 | |
| 6468 |
jinmuk
|
12년 전 | 5569 | |
| 6467 | 12년 전 | 693 | ||
| 6466 |
jinmuk
|
12년 전 | 2266 | |
| 6465 |
jinmuk
|
12년 전 | 6731 | |
| 6464 |
jinmuk
|
12년 전 | 2404 | |
| 6463 |
jinmuk
|
12년 전 | 9324 | |
| 6462 |
희망과열정
|
12년 전 | 526 | |
| 6461 |
Header
|
12년 전 | 722 | |
| 6460 |
희망과열정
|
12년 전 | 1350 | |
| 6459 |
프리랜서개발자
|
12년 전 | 1671 | |
| 6458 | 12년 전 | 1329 | ||
| 6457 |
jinmuk
|
12년 전 | 1936 | |
| 6456 |
jinmuk
|
12년 전 | 2342 | |
| 6455 |
jinmuk
|
12년 전 | 3199 | |
| 6454 |
jinmuk
|
12년 전 | 2166 | |
| 6453 |
jinmuk
|
12년 전 | 2344 | |
| 6452 |
jinmuk
|
12년 전 | 2310 | |
| 6451 |
jinmuk
|
12년 전 | 1591 | |
| 6450 |
jinmuk
|
12년 전 | 1394 | |
| 6449 |
jinmuk
|
12년 전 | 1037 | |
| 6448 |
jinmuk
|
12년 전 | 1232 | |
| 6447 |
jinmuk
|
12년 전 | 2003 | |
| 6446 |
jinmuk
|
12년 전 | 1563 | |
| 6445 |
jinmuk
|
12년 전 | 1263 | |
| 6444 |
jinmuk
|
12년 전 | 2304 | |
| 6443 |
jinmuk
|
12년 전 | 2042 | |
| 6442 |
jinmuk
|
12년 전 | 1882 | |
| 6441 |
jinmuk
|
12년 전 | 1615 | |
| 6440 |
jinmuk
|
12년 전 | 2314 | |
| 6439 |
jinmuk
|
12년 전 | 1134 | |
| 6438 |
wndProc
|
12년 전 | 775 | |
| 6437 | 12년 전 | 393 | ||
| 6436 |
senseme
|
12년 전 | 541 | |
| 6435 | 12년 전 | 1043 | ||
| 6434 | 12년 전 | 2473 | ||
| 6433 | 12년 전 | 2479 | ||
| 6432 | 12년 전 | 1557 | ||
| 6431 |
밥먹고합시다
|
12년 전 | 1185 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기