Java邀请码生成小工具

匿名 (未验证) 提交于 2019-12-02 21:53:52

import org.springframework.util.Assert;  import java.util.HashSet; import java.util.Iterator; import java.util.Random; import java.util.Set;  public class InviteCodeUtil {     public static String generateInviteCode(int len) {         Assert.isTrue(len > 0, "长度要大于0");          char[] chars = {'Q', 'W', 'E', '8', 'S', '2', 'D', 'Z',                 'X', '9', 'C', '7', 'P', '5', 'K', '3',                 'M', 'J', 'U', 'F', 'R', '4', 'V', 'Y',                 'T', 'N', '6', 'B', 'G', 'H', 'A', 'L'};         Random random = new Random();         char[] inviteChars = new char[len];         for (int i = 0; i < len; i++) {             inviteChars[i] = chars[random.nextInt(chars.length)];         }         return String.valueOf(inviteChars);     }      public static void main(String[] args) {         long start = System.currentTimeMillis();         Set set = new HashSet();         for (int i = 0; i < 1000000; i++) {             set.add(generateInviteCode(6));         }         Iterator iterator = set.iterator();         for (int i =0;i<10;i++){             System.out.println(iterator.next());         }         System.out.println();         System.out.println(set.size());     } }

B76BS3 994UXZ Z5H933 VTDP24 AV6BSB GZMLHF ZEDPSM FWKMZY BKD5HA RSH6LR  999536
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!