JavaScript如何生成随机字符串和随机数字
JavaScript可使用Math.random()函数生成随机字符串和随机数字
使用js生成随机字符串
function randomString(e) {
e = e || 32;
var t = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz",
a = t.length,
n = "";
for (i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a));
return n
}
使用js生成随机数字
function GetRandomNum(Min, Max) {
var Range = Max - Min;
var Rand = Math.random();
return (Min + Math.round(Rand * Range));
}
JS生成随机字符串和随机数字还是很简单的,哈哈哈!