public void createNumber(){
int[] randoms = {1,2,3,4,5,6,7,8,9,10,11,12};
Random randX = new Random();
int x = 0;
int count = 0;
while(count != 12) {
x = randX .nextInt(11);
if(randoms[x] != -1) {
System.out.println(randoms[x]);
randoms[x] = -1;
count ++;
}
}
}
/**
* 根据传入的长度 反回对应长度随机数字
*
* @param pwd_len
* 长度
* @return String
*/
public String genRandomNum(int pwd_len)
{
int count = 0;
char str[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
StringBuffer pwd = new StringBuffer("");
Random r = new Random();
while (count < pwd_len) {
int i = Math.abs(r.nextInt(10));
if (i >= 0 && i < str.length)
{
pwd.append(str[i]);
count++;
}
}
return pwd.toString();
}
oracle :中生成随机数
select substr(cast(dbms_random.value as varchar2(38)),3,6) from dual;
阅读(1460) | 评论(0) | 转发(1) |