<?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년 전
중복되는 카운트가 존재할 여지는 있겠네요
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 8230 | 9년 전 | 92 | ||
| 8229 | 9년 전 | 87 | ||
| 8228 |
커네드커네드
|
9년 전 | 128 | |
| 8227 | 9년 전 | 148 | ||
| 8226 | 9년 전 | 178 | ||
| 8225 | 9년 전 | 168 | ||
| 8224 | 9년 전 | 163 | ||
| 8223 | 9년 전 | 127 | ||
| 8222 |
|
9년 전 | 202 | |
| 8221 | 9년 전 | 107 | ||
| 8220 | 9년 전 | 126 | ||
| 8219 | 9년 전 | 115 | ||
| 8218 | 9년 전 | 162 | ||
| 8217 |
star3840
|
9년 전 | 128 | |
| 8216 | 9년 전 | 176 | ||
| 8215 | 9년 전 | 133 | ||
| 8214 | 9년 전 | 240 | ||
| 8213 | 9년 전 | 180 | ||
| 8212 | 9년 전 | 97 | ||
| 8211 | 9년 전 | 272 | ||
| 8210 | 9년 전 | 266 | ||
| 8209 | 9년 전 | 356 | ||
| 8208 | 9년 전 | 239 | ||
| 8207 | 9년 전 | 243 | ||
| 8206 |
|
9년 전 | 210 | |
| 8205 | 9년 전 | 189 | ||
| 8204 | 9년 전 | 151 | ||
| 8203 | 9년 전 | 246 | ||
| 8202 | 9년 전 | 162 | ||
| 8201 | 9년 전 | 194 | ||
| 8200 | 9년 전 | 180 | ||
| 8199 | 9년 전 | 236 | ||
| 8198 | 9년 전 | 195 | ||
| 8197 | 9년 전 | 182 | ||
| 8196 | 9년 전 | 569 | ||
| 8195 | 9년 전 | 178 | ||
| 8194 | 9년 전 | 302 | ||
| 8193 | 9년 전 | 177 | ||
| 8192 | 9년 전 | 216 | ||
| 8191 | 9년 전 | 160 | ||
| 8190 | 9년 전 | 152 | ||
| 8189 | 9년 전 | 215 | ||
| 8188 | 9년 전 | 150 | ||
| 8187 | 9년 전 | 162 | ||
| 8186 | 9년 전 | 158 | ||
| 8185 | 9년 전 | 335 | ||
| 8184 | 9년 전 | 126 | ||
| 8183 | 9년 전 | 338 | ||
| 8182 | 9년 전 | 192 | ||
| 8181 | 9년 전 | 150 | ||
| 8180 | 9년 전 | 719 | ||
| 8179 | 9년 전 | 505 | ||
| 8178 | 9년 전 | 325 | ||
| 8177 |
kiplayer
|
9년 전 | 346 | |
| 8176 | 9년 전 | 376 | ||
| 8175 | 9년 전 | 243 | ||
| 8174 | 9년 전 | 266 | ||
| 8173 | 9년 전 | 357 | ||
| 8172 | 9년 전 | 218 | ||
| 8171 | 9년 전 | 196 | ||
| 8170 | 9년 전 | 311 | ||
| 8169 |
커네드커네드
|
9년 전 | 275 | |
| 8168 | 9년 전 | 343 | ||
| 8167 | 9년 전 | 335 | ||
| 8166 | 9년 전 | 255 | ||
| 8165 | 9년 전 | 189 | ||
| 8164 | 9년 전 | 319 | ||
| 8163 | 9년 전 | 301 | ||
| 8162 | 9년 전 | 321 | ||
| 8161 | 9년 전 | 314 | ||
| 8160 |
|
9년 전 | 509 | |
| 8159 | 9년 전 | 446 | ||
| 8158 | 9년 전 | 270 | ||
| 8157 | 9년 전 | 399 | ||
| 8156 | 9년 전 | 285 | ||
| 8155 | 9년 전 | 275 | ||
| 8154 |
00년생용띠
|
9년 전 | 618 | |
| 8153 | 9년 전 | 253 | ||
| 8152 |
|
9년 전 | 431 | |
| 8151 | 9년 전 | 432 | ||
| 8150 | 9년 전 | 524 | ||
| 8149 |
Jangfolk
|
9년 전 | 367 | |
| 8148 | 9년 전 | 188 | ||
| 8147 | 9년 전 | 394 | ||
| 8146 | 9년 전 | 464 | ||
| 8145 | 9년 전 | 412 | ||
| 8144 | 9년 전 | 371 | ||
| 8143 | 9년 전 | 216 | ||
| 8142 | 9년 전 | 452 | ||
| 8141 | 9년 전 | 397 | ||
| 8140 | 9년 전 | 944 | ||
| 8139 | 9년 전 | 282 | ||
| 8138 |
전갈자리남자
|
9년 전 | 408 | |
| 8137 | 9년 전 | 416 | ||
| 8136 | 9년 전 | 764 | ||
| 8135 |
|
9년 전 | 811 | |
| 8134 |
PlayPixel
|
9년 전 | 537 | |
| 8133 |
|
9년 전 | 459 | |
| 8132 | 9년 전 | 478 | ||
| 8131 | 9년 전 | 827 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기