function randomString(e) { e = e || 32; var t = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678", a = t.length, n = ""; for (i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a)); return n } alert(randomString(6));
// 本例子表明生成100000-999999的隨機數 function GetRandomNum(Min,Max) { var Range = Max - Min; var Rand = Math.random(); return(Min + Math.round(Rand * Range)); } var num = GetRandomNum(10000,999999); alert(num);
var str = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']; function generateMixed(n) { var res = ""; for(var i = 0; i < n ; i ++) { var id = Math.ceil(Math.random()*35); res += str[id]; } return res; } alert(generateMixed(6));
//Math.random() 生成隨機數字, eg: 0.123456 //.toString(36) 轉化成36進制 : "0.4fzyo82mvyr" //.slice(-8); 截取最後八位 : "yo82mvyr" var str = Math.random().toString(36).slice(-6); alert(str);
function randomString(length) { var str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; var result = ''; for (var i = length; i > 0; --i) result += str[Math.floor(Math.random() * str.length)]; return result; } alert(randomString(6));
Author:TANKING
Date:2020-05-22
Web:https://www.likeyunba.com/
WeChat:face6009數組