Chinaunix首页 | 论坛 | 博客
  • 博客访问: 29557
  • 博文数量: 32
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 15
  • 用 户 组: 普通用户
  • 注册时间: 2015-05-14 09:52
文章分类

全部博文(32)

文章存档

2015年(32)

我的朋友

分类: Java

2015-05-14 10:24:51

原文地址:产生随机数的方法 作者:yong_kang

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;
阅读(331) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~