随机生成8位数授权码

来源:互联网 发布:网络男歌手比较慢的歌 编辑:程序博客网 时间:2024/04/26 13:51
package com.bwsk.modules.weixin.util;

import java.util.Random;
/**
 *随机生成8位数授权码
 *百望金赋
 * @author liyapeng
 *
 */
public class RandomUtils {
    //生成8位数的 字母 大小随机  当做授权码
    public static String randomUtil(){
        Random r = new Random();
          String code = "";
          for (int i = 0; i < 8; ++i) {
              int temp = r.nextInt(52);
              char x = (char) (temp < 26 ? temp + 97 : (temp % 26) + 65);
              code += x;
          }
          return code;
    }

}

0 0
原创粉丝点击