随机生成4位不同数字
import java.util.Random;
/**
*
* Class Name: FourRandomUtils.java
* Function:
* 自动生成四位不相同的数字
* Modifications:
*
* @author zhou DateTime 2017年7月27日 上午11:18:32
* @version 1.0
*/
public class FourRandomUtils {
public static String getFourNum() {
Random r=new Random();
int tag[]={0,0,0,0,0,0,0,0,0,0};
String four="";
int temp=0;
while(four.length()!=4){
temp=r.nextInt(10);//随机获取0~9的数字
if(tag[temp]==0){
four+=temp;
tag[temp]=1;
}
}
return four;
}
}