random.js 522 B

12345678910111213141516
  1. /*
  2. * @Author: awj
  3. * @Date: 2020-03-23 18:57:52
  4. * @LastEditors: awj
  5. * @LastEditTime: 2020-03-23 19:03:50
  6. * @Description: description
  7. */
  8. export function getRandomString(len = 10) {
  9. const chars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678"; /** **默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
  10. const maxPos = chars.length;
  11. let randomString = "";
  12. for (let i = 0; i < len; i++) {
  13. randomString += chars.charAt(Math.floor(Math.random() * maxPos));
  14. }
  15. return randomString;
  16. }