<?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년 전
중복되는 카운트가 존재할 여지는 있겠네요
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 8030 | 9년 전 | 387 | ||
| 8029 | 9년 전 | 316 | ||
| 8028 | 9년 전 | 274 | ||
| 8027 | 9년 전 | 288 | ||
| 8026 | 9년 전 | 352 | ||
| 8025 | 9년 전 | 392 | ||
| 8024 | 9년 전 | 352 | ||
| 8023 | 9년 전 | 401 | ||
| 8022 | 9년 전 | 324 | ||
| 8021 | 9년 전 | 336 | ||
| 8020 | 9년 전 | 327 | ||
| 8019 | 9년 전 | 347 | ||
| 8018 | 9년 전 | 454 | ||
| 8017 | 9년 전 | 540 | ||
| 8016 | 9년 전 | 340 | ||
| 8015 | 9년 전 | 398 | ||
| 8014 | 9년 전 | 330 | ||
| 8013 | 9년 전 | 245 | ||
| 8012 | 9년 전 | 251 | ||
| 8011 | 9년 전 | 452 | ||
| 8010 | 9년 전 | 308 | ||
| 8009 | 9년 전 | 303 | ||
| 8008 | 9년 전 | 292 | ||
| 8007 | 9년 전 | 435 | ||
| 8006 | 9년 전 | 470 | ||
| 8005 |
|
9년 전 | 975 | |
| 8004 | 9년 전 | 365 | ||
| 8003 | 9년 전 | 428 | ||
| 8002 | 9년 전 | 326 | ||
| 8001 |
|
9년 전 | 669 | |
| 8000 | 9년 전 | 431 | ||
| 7999 | 9년 전 | 382 | ||
| 7998 | 9년 전 | 438 | ||
| 7997 | 9년 전 | 318 | ||
| 7996 | 9년 전 | 542 | ||
| 7995 | 9년 전 | 464 | ||
| 7994 | 9년 전 | 344 | ||
| 7993 | 9년 전 | 406 | ||
| 7992 | 9년 전 | 519 | ||
| 7991 | 9년 전 | 260 | ||
| 7990 | 9년 전 | 300 | ||
| 7989 | 9년 전 | 313 | ||
| 7988 | 9년 전 | 738 | ||
| 7987 | 9년 전 | 437 | ||
| 7986 | 9년 전 | 433 | ||
| 7985 | 9년 전 | 514 | ||
| 7984 | 9년 전 | 439 | ||
| 7983 | 9년 전 | 668 | ||
| 7982 | 9년 전 | 533 | ||
| 7981 | 9년 전 | 485 | ||
| 7980 | 9년 전 | 506 | ||
| 7979 | 9년 전 | 488 | ||
| 7978 | 9년 전 | 463 | ||
| 7977 | 9년 전 | 403 | ||
| 7976 | 9년 전 | 859 | ||
| 7975 | 9년 전 | 371 | ||
| 7974 | 9년 전 | 405 | ||
| 7973 | 9년 전 | 605 | ||
| 7972 | 9년 전 | 392 | ||
| 7971 | 9년 전 | 466 | ||
| 7970 | 9년 전 | 308 | ||
| 7969 | 9년 전 | 551 | ||
| 7968 | 9년 전 | 391 | ||
| 7967 | 9년 전 | 381 | ||
| 7966 | 9년 전 | 380 | ||
| 7965 |
|
9년 전 | 1021 | |
| 7964 | 9년 전 | 409 | ||
| 7963 | 9년 전 | 407 | ||
| 7962 | 9년 전 | 393 | ||
| 7961 |
전갈자리남자
|
9년 전 | 512 | |
| 7960 | 9년 전 | 974 | ||
| 7959 | 9년 전 | 558 | ||
| 7958 | 9년 전 | 416 | ||
| 7957 | 9년 전 | 372 | ||
| 7956 | 9년 전 | 373 | ||
| 7955 | 9년 전 | 466 | ||
| 7954 | 9년 전 | 391 | ||
| 7953 | 9년 전 | 441 | ||
| 7952 | 9년 전 | 362 | ||
| 7951 | 9년 전 | 506 | ||
| 7950 | 9년 전 | 400 | ||
| 7949 | 9년 전 | 394 | ||
| 7948 | 9년 전 | 330 | ||
| 7947 | 9년 전 | 944 | ||
| 7946 | 9년 전 | 447 | ||
| 7945 | 9년 전 | 404 | ||
| 7944 | 9년 전 | 437 | ||
| 7943 | 9년 전 | 391 | ||
| 7942 | 9년 전 | 410 | ||
| 7941 | 9년 전 | 403 | ||
| 7940 | 9년 전 | 896 | ||
| 7939 | 9년 전 | 363 | ||
| 7938 | 9년 전 | 399 | ||
| 7937 | 9년 전 | 291 | ||
| 7936 | 9년 전 | 891 | ||
| 7935 | 9년 전 | 457 | ||
| 7934 | 9년 전 | 431 | ||
| 7933 | 9년 전 | 535 | ||
| 7932 | 9년 전 | 499 | ||
| 7931 | 9년 전 | 553 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기