怎么用Java产生不重复的邀请码

2025-03-13 19:05:38
推荐回答(1个)
回答1:

//生成十位数奖品兑换码
public static void test13() throws Exception{
    int count = 10;
    String str="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    StringBuilder sb = new StringBuilder();
    Random r = new Random(System.currentTimeMillis());
    for (int i = 0; i < count; i++) {
        int d =r.nextInt(62);
        sb.append(str.charAt(d));
    }
    System.out.println(sb.toString());
}