随机生成四位不同数字
2017-07-30 11:47
295 查看
随机生成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;
}
}
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;
}
}
相关文章推荐
- 明明想在学校中请一些同学一起做一项问卷调查,为了实验的客观性,他先用计算机生成了N个1到1000之间的随机整数(N≤1000),对于其中重复的数字,只保留一个,把其余相同的数去掉,不同的数对应着不同的学生的学号。然后再把这些数从
- 随机生成n个不同的数字小组合作编写
- 随机生成n个不同的数字-小组合作编写
- Android数字游戏之数独(自动随机生成不同难度的数独)
- 随机生成四位数字
- 随机生成双色球彩票红,蓝数字
- [转]java生成随机数字和字母组合
- Java随机生成长度不少于6的指定长度的密码,且这个字符串必须包含大小写字母、数字和特殊字符,四种的任意三种
- java 生成随机码 字符数字图片等
- 根据时间随机生成12位数字,且不重复2015-8-21
- Asp.NET 生成随机码基类(随机字母,随机数字,随机字母+数字 )
- 基于MNIST数据集通过朴素贝叶斯学习生成随机手写体数字图像
- 如何使用rand函数&随机生成80以上的数字
- 【java】随机生成6位的数字
- *自创*可变长度随机数字/字母的生成小结(针对文件上传及验证码)
- C# .NET Random 生成随机数字和字母
- java生成四位随机数,包含数字和字母
- java验证码中的数字、字母、汉字如何随机生成
- ORACLE自动生成8位带数字和字母的随机密码