利用随机数生成方法产生激活码,形如12HJ-9Hjf-HHTY-KK8G
2015-01-13 19:03
417 查看
产生一个激活码
产生十个激活码(外面多套一层循环)
package jihuoma; //产生激活码:类似于2Hs0-ssKj-9HHo-A55D public class Test { public static void main(String[] args) { String str=""; for (int i = 1; i <= 16; i++) { int a=(int)(Math.random()*3);//0,1,2,[0,3)之间取整数 if(a==0) { str=str+(char)((int)(Math.random()*('Z'-'A'+1))+'A'); } if(a==1) { str=str+(char)((int)(Math.random()*('z'-'a'+1))+'a'); } if(a==2) { str=str+(char)((int)(Math.random()*('9'-'0'+1))+'0'); } if(i%4==0&&i<16)//每4个之间加一个-代表分开,等于16时就不用再加上-了。 { str=str+'-'; } } System.out.println(str);//打印输出随机产生的激活码 } }
产生十个激活码(外面多套一层循环)
package jihuoma; //产生10个激活码 public class Test2 { public static void main(String[] args) { for (int j = 0; j < 10; j++) {//循环10次,产生10个激活码 String str=""; for (int i = 1; i <= 16; i++) {//循环完16次后产生一个激活码 int a=(int)(Math.random()*3);//0,1,2 if(a==0) { str=str+(char)((int)(Math.random()*('Z'-'A'+1))+'A'); } if(a==1) { str=str+(char)((int)(Math.random()*('z'-'a'+1))+'a'); } if(a==2) { str=str+(char)((int)(Math.random()*('9'-'0'+1))+'0'); } if(i%4==0&&i<16) { str=str+'-'; } } System.out.println(str); } } }
相关文章推荐
- 一种利用ADC产生随机数的方法
- 利用Math.Random()方法来生成随机数。(转)
- linux下 C语言随机数生成方法rand(产生随机数)
- 【Java】利用Collections类下的shuffle洗牌方法改进在一定的范围内产生不重复的随机数
- 利用Golang生成整数随机数方法示例
- VC++中产生为随机数的简单方法
- 从易到难编写C++程序,(6)问题:利用问题(5)的随机数生成实现发牌
- 生成无重复随机数的2种方法
- Symbian生成随机数的方法
- 利用/dev/random生成随机数
- 利用SQL存储过程生成程序编号的一种方法
- 利用SQL存储过程生成程序编号的一种方法(转)
- JavaScript中利用doucument.writeline()方法预生成代码的小技巧
- 生成无重复随机数的2种方法
- 利用Render方法生成静态页
- 利用SQL存储过程生成程序编号的一种方法
- 产生一定范围内随机数的方法
- java生成无重复随机数的2种方法
- 利用struts commons BeanUtils写的一个自动生成toString()方法的工具
- 一个生成不重复随机数的方法