生成16位激活码

/**
 * @Title随机生成16为大小写字母+数字
 * @return String 
 * */
public String getCharAndNumr()     
{     
   String val = "";     
   Random random = new Random();     
   for(int i = 0; i < 16; i++)     
   {     
       String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num"; // 输出字母还是数字     
       if("char".equalsIgnoreCase(charOrNum)) // 字符串     
       {     
         int choice = random.nextInt(2) % 2 == 0 ? 65 : 97; //取得大写字母还是小写字母     
         val += (char) (choice + random.nextInt(26));     
       }     
       else if("num".equalsIgnoreCase(charOrNum)) // 数字     
       {     
         val += String.valueOf(random.nextInt(10));     
       }     
   }     
            
   return val;     
}   

public String giveCode(){
String createcode="";
String changecode="";
ActivationCode o=new ActivationCode();
createcode=o.getCharAndNumr();//得到一串创建的字符
for(int i=0;i<createcode.length();){
changecode+=createcode.substring(i, i+4)+"-";//用for循环给创建的字符串每隔4个加上“-”
i=i+4;
}
changecode=changecode.substring(0, changecode.length()-1);//把最后面的“-”截去
return changecode;


}



欢迎大家加入java资源免费分享群,群号:814657026

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值