<?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년 전 | 347 | ||
| 8029 | 9년 전 | 282 | ||
| 8028 | 9년 전 | 251 | ||
| 8027 | 9년 전 | 262 | ||
| 8026 | 9년 전 | 303 | ||
| 8025 | 9년 전 | 365 | ||
| 8024 | 9년 전 | 325 | ||
| 8023 | 9년 전 | 378 | ||
| 8022 | 9년 전 | 305 | ||
| 8021 | 9년 전 | 308 | ||
| 8020 | 9년 전 | 304 | ||
| 8019 | 9년 전 | 327 | ||
| 8018 | 9년 전 | 429 | ||
| 8017 | 9년 전 | 525 | ||
| 8016 | 9년 전 | 315 | ||
| 8015 | 9년 전 | 380 | ||
| 8014 | 9년 전 | 311 | ||
| 8013 | 9년 전 | 224 | ||
| 8012 | 9년 전 | 236 | ||
| 8011 | 9년 전 | 435 | ||
| 8010 | 9년 전 | 287 | ||
| 8009 | 9년 전 | 273 | ||
| 8008 | 9년 전 | 274 | ||
| 8007 | 9년 전 | 417 | ||
| 8006 | 9년 전 | 453 | ||
| 8005 |
|
9년 전 | 954 | |
| 8004 | 9년 전 | 336 | ||
| 8003 | 9년 전 | 407 | ||
| 8002 | 9년 전 | 315 | ||
| 8001 |
|
9년 전 | 654 | |
| 8000 | 9년 전 | 399 | ||
| 7999 | 9년 전 | 361 | ||
| 7998 | 9년 전 | 413 | ||
| 7997 | 9년 전 | 303 | ||
| 7996 | 9년 전 | 528 | ||
| 7995 | 9년 전 | 437 | ||
| 7994 | 9년 전 | 278 | ||
| 7993 | 9년 전 | 360 | ||
| 7992 | 9년 전 | 498 | ||
| 7991 | 9년 전 | 233 | ||
| 7990 | 9년 전 | 259 | ||
| 7989 | 9년 전 | 290 | ||
| 7988 | 9년 전 | 713 | ||
| 7987 | 9년 전 | 409 | ||
| 7986 | 9년 전 | 397 | ||
| 7985 | 9년 전 | 492 | ||
| 7984 | 9년 전 | 420 | ||
| 7983 | 9년 전 | 638 | ||
| 7982 | 9년 전 | 500 | ||
| 7981 | 9년 전 | 446 | ||
| 7980 | 9년 전 | 473 | ||
| 7979 | 9년 전 | 448 | ||
| 7978 | 9년 전 | 424 | ||
| 7977 | 9년 전 | 363 | ||
| 7976 | 9년 전 | 834 | ||
| 7975 | 9년 전 | 351 | ||
| 7974 | 9년 전 | 378 | ||
| 7973 | 9년 전 | 583 | ||
| 7972 | 9년 전 | 369 | ||
| 7971 | 9년 전 | 439 | ||
| 7970 | 9년 전 | 284 | ||
| 7969 | 9년 전 | 529 | ||
| 7968 | 9년 전 | 369 | ||
| 7967 | 9년 전 | 350 | ||
| 7966 | 9년 전 | 353 | ||
| 7965 |
|
9년 전 | 1002 | |
| 7964 | 9년 전 | 389 | ||
| 7963 | 9년 전 | 372 | ||
| 7962 | 9년 전 | 358 | ||
| 7961 |
전갈자리남자
|
9년 전 | 497 | |
| 7960 | 9년 전 | 947 | ||
| 7959 | 9년 전 | 539 | ||
| 7958 | 9년 전 | 394 | ||
| 7957 | 9년 전 | 356 | ||
| 7956 | 9년 전 | 362 | ||
| 7955 | 9년 전 | 430 | ||
| 7954 | 9년 전 | 353 | ||
| 7953 | 9년 전 | 414 | ||
| 7952 | 9년 전 | 339 | ||
| 7951 | 9년 전 | 486 | ||
| 7950 | 9년 전 | 370 | ||
| 7949 | 9년 전 | 378 | ||
| 7948 | 9년 전 | 313 | ||
| 7947 | 9년 전 | 915 | ||
| 7946 | 9년 전 | 409 | ||
| 7945 | 9년 전 | 377 | ||
| 7944 | 9년 전 | 384 | ||
| 7943 | 9년 전 | 355 | ||
| 7942 | 9년 전 | 391 | ||
| 7941 | 9년 전 | 378 | ||
| 7940 | 9년 전 | 865 | ||
| 7939 | 9년 전 | 315 | ||
| 7938 | 9년 전 | 361 | ||
| 7937 | 9년 전 | 262 | ||
| 7936 | 9년 전 | 865 | ||
| 7935 | 9년 전 | 423 | ||
| 7934 | 9년 전 | 390 | ||
| 7933 | 9년 전 | 466 | ||
| 7932 | 9년 전 | 448 | ||
| 7931 | 9년 전 | 503 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기