First type:
The code from http://caibaojian.com/js-random-string.html
function Makeid ()
{
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (Var i=0 i < 5; i++)
text + possible.charat (Math.floor (Math.random () * possible.length));
return text;
Second: Do not need to enter the character set together
function RandomString (L) {
var s= ';
var randomchar=function () {
var n= math.floor (Math.random () *62);
if (n<10) return n; 1-10
if (n<36) return String.fromCharCode (n+55),//a-z return
string.fromcharcode (n+61);//a-z
} While
(s.length< L) s+= Randomchar ();
return s;
}
alert(randomstring(5))
Third: Supports custom character length and feature character set combination
function RandomString (len, charSet) {
CharSet = CharSet | | ' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ';
var randomstring = ';
for (var i = 0; i < len; i++) {
var randompoz = Math.floor (Math.random () * charset.length);
RandomString + = charset.substring (randompoz,randompoz+1);
}
return randomstring;
}
Call with default CharSet [a-za-z0-9] or send in your own:
var randomvalue = RandomString (5);
var randomvalue = randomstring (5, ' pickcharsfromthisset ');
Demo screenshot
The above is JavaScript to create a random string with digital letters three methods summary, there is a need to reference learning.