随机生成字符的另一种玩法。
根据学习JavaScript笔记这段代码:
var rand =(min,max)=>Math.round(Math.random()*(max-min))+min;
下面的这行代码:
while(result.length<length) result+=String.fromCharCode(Math.round(Math.random()*(rangeMax-rangeMin))-rangeMin);
应该修改为:
while(result.length<length) result+=String.fromCharCode(Math.round(Math.random()*(rangeMax-rangeMin))+rangeMin);
随机从数组中取出一个东东。
returnthis.length?Math.round(Math.random()*(this.length-1)):undefined;// 如果长度为 0,返回 undefined
修改为:
returnthis[(this.length?Math.round(Math.random()*(this.length-1)):undefined)];// 如果长度为 0,返回 undefined
这样比较符合对象的一般调用方式。