标签:随机 stat pack generate class ring int public rgs
package Shoot; import java.util.Arrays; import java.util.Random; public class Generate { public static void main(String[] args) { char [] b =generate(); System.out.println(Arrays.toString(b)); } public static char[] generate() { Random ran=new Random(); char[] letter = new char[26]; for(int i = 0;i<letter.length;i++) { letter[i]=(char) (65+i); } int index = 0; int i = 0; boolean[] flag = new boolean[letter.length]; //System.out.println(Arrays.toString(flag)); char [] ch = new char[4]; while(index<ch.length) { i = ran.nextInt(letter.length); if(flag[i]) { continue; } //i = ran.nextInt(letter.length); //i=(int)(Math.random()*27); ch[index]=letter[i]; flag[i]=true; index++; } return ch; } }标签:随机 stat pack generate class ring int public rgs
原文地址:http://blog.51cto.com/10972685/2069628