"함수 base62gen()"의 두 판 사이의 차이

12번째 줄: 12번째 줄:
console.log( base62gen(10) ); // 34OSAoyw6A
console.log( base62gen(10) ); // 34OSAoyw6A
console.log( base62gen(20) ); // xVT1o9XdVffAcWzPfFgH
console.log( base62gen(20) ); // xVT1o9XdVffAcWzPfFgH
</source>
==PHP==
[[분류: PHP]]
<source lang='PHP'>
function base62gen($len) {
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$result = '';
for( $i=0; $i<$len ;$i++ ) $result .= $chars[mt_rand(0, 61)];
return $result;
}
var_dump( base62gen(10) ); // string(10) "x55a6xeJm7"
var_dump( base62gen(20) ); // string(20) "w9WIVYj0Fq6UlmYdwBEw"
</source>
</source>



2016년 2월 13일 (토) 20:28 판


1 JavaScript

function base62gen(len) {
	var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'.split('');
	var result = '';
	for(i=0; i<len; i++) result += chars[0|Math.random()*62];
	return result;
}
console.log( base62gen(10) ); // 34OSAoyw6A
console.log( base62gen(20) ); // xVT1o9XdVffAcWzPfFgH

2 PHP

function base62gen($len) {
	$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
	$result = '';
	for( $i=0; $i<$len ;$i++ ) $result .= $chars[mt_rand(0, 61)];
	return $result;
}
var_dump( base62gen(10) ); // string(10) "x55a6xeJm7"
var_dump( base62gen(20) ); // string(20) "w9WIVYj0Fq6UlmYdwBEw"

3 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}