码迷,mamicode.com
首页 > Web开发 > 详细

js 获取随机字符串

时间:2016-03-19 06:40:16      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:js 随机字符串

function randomString(len) {

  len = len || 32;

  var $chars = ‘ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678‘;    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/

  var maxPos = $chars.length;

  var pwd = ‘‘;

  for (i = 0; i < len; i++) {

    pwd += $chars.charAt(Math.floor(Math.random() * maxPos));

  }

  return pwd;

}


js 获取随机字符串

标签:js 随机字符串

原文地址:http://xuanxy.blog.51cto.com/2357481/1752666

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!