Chinaunix首页 | 论坛 | 博客
  • 博客访问: 251959
  • 博文数量: 65
  • 博客积分: 2026
  • 博客等级: 大尉
  • 技术积分: 695
  • 用 户 组: 普通用户
  • 注册时间: 2006-02-12 14:34
文章分类

全部博文(65)

文章存档

2012年(1)

2011年(1)

2010年(1)

2009年(2)

2008年(7)

2007年(6)

2006年(47)

我的朋友

分类: Java

2006-04-04 10:18:58

/**
 * 本类生成随机数字组成的字符串
 */
package merp.ldap.tools;
import java.lang.Math;
/**
 * @author wd
 *
 */
public class RandomNum
{
 /**
  * 得到一位的随机数字
  * @return
  */
 private static int getARandomNum()
 {
  int i;
  double d;
  
  d=Math.random();
  i= (int)(d*10);
  return i;
  
 }
 
 
 /**
  * 得到随即数字组成的字符串
  * @param NumLen 字符串长度 即几位数字
  * @return
  */
 public static String getRandomNumStr(int NumLen)
 {
  String s="";
  int i,n;
  
  for (i=0;i  {
   n=RandomNum.getARandomNum();
   s+=n;
  }
  return s;
 }
 
 public static void main(String[] args)
 {
  String s=RandomNum.getRandomNumStr(5);
  
  System.out.println(s);
 }
 
}
阅读(2890) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~