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

1번째 줄: 1번째 줄:
[[분류: Base62]]
[[분류: Base62]]
==Bash==
[[분류: Bash]]
<source lang='Bash'>
cat /dev/urandom | tr -cd "[:alnum:]" | head -c 10
# ZKal8Csw97
cat /dev/urandom | tr -cd "[:alnum:]" | head -c 20
# PLulj82jvO50DlpazTmV
</source>


==JavaScript==
==JavaScript==

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


1 Bash

cat /dev/urandom | tr -cd "[:alnum:]" | head -c 10 
# ZKal8Csw97
cat /dev/urandom | tr -cd "[:alnum:]" | head -c 20
# PLulj82jvO50DlpazTmV

2 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

3 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"

4 같이 보기

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