random_str.js 956 B

12345678910111213141516171819
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. // 生成随机字符串
  11. export default function (len = 32) {
  12. const $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
  13. const maxPos = $chars.length;
  14. let str = '';
  15. for (let i = 0; i < len; i++) {
  16. str += $chars.charAt(Math.floor(Math.random() * maxPos));
  17. }
  18. return str;
  19. }