当前位置: 首页 > 工具软件 > OpenID4Java > 使用案例 >

Java模拟生成OPENID

端木弘方
2023-12-01
public static void main(String[] args) {
    for(int i = 0; i < 10; i++) {
        // 增加标识,OPENID默认28位
        System.out.println("o2xSPw" + genRandomNum());
    }
}

public static String genRandomNum(){
    int  maxNum = 37;
    int count = 0;
    char[] str = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
            'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
            'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-' };
    StringBuffer buffer = new StringBuffer();
    Random r = new Random();
    while(count < 22){
        int i = Math.abs(r.nextInt(maxNum));
        if (i >= 0 && i < str.length) {
            buffer.append(str[i]);
            count ++;
        }
    }
    return buffer.toString();
}

输出结果:
o2xSPwJG-9GLJISGT79-ITJKV4V0
o2xSPwRFRZGUPLD-0RTKAEJRXJ5N
o2xSPwLS3EJXHD3ATGIPCDP4KVH5
o2xSPw98RWXXENMM8C9WMMSIIBEI
o2xSPwAWFNJQ4JV80HGZCR4C-O8W
o2xSPw9YF21KCMRZOHZOR4KJ9JY8
o2xSPwB-U-QHT17-U6EWU3YN4ARY
o2xSPwJUQBZ2NE8U8R4LL8OA84HD
o2xSPwDGBR9OBRPEDSZSAOQC74MI
o2xSPw1YYXQWDJDIUYDKP1R0UUY3

简单记录下。供大家参考,感谢各位观看。

 类似资料: