Apache's___Tomcat

Java Vs .Net

常用链接

统计

Blogs

Mobile

Program

最新评论

生成随机的字符串

2006年3月17日11:30:27

 1 public   class  ttttt  {
 2

 3      private   static   char [] rst  =   new   char [ 30
];
 4

 5      private   static   char [] ch  =  
{  ' \\ ' ,  ' ^ ' ,  ' | ' ,  ' ~ ' ,  ' ? ' ,  ' _ ' ,  ' - ' ,  ' @ ' ,
 6              ' # ' ,  ' $ ' ,  ' % ' ,  ' ! ' ,  ' + ' ,  ' - ' ,  ' * ' ,  ' / ' ,  ' 0 ' ,  ' 1 ' ,  ' 2 ' ,  ' 3 ' ,  ' 4 '
,
 7              ' 5 ' ,  ' 6 ' ,  ' 7 ' ,  ' 8 ' ,  ' 9 ' ,  ' a ' ,  ' b ' ,  ' c ' ,  ' d ' ,  ' e ' ,  ' f ' ,  ' g ' ,  ' h '
,
 8              ' i ' ,  ' j ' ,  ' k ' ,  ' l ' ,  ' m ' ,  ' n ' ,  ' o ' ,  ' p ' ,  ' q ' ,  ' r ' ,  ' s ' ,  ' t ' ,  ' u '
,
 9              ' v ' ,  ' w ' ,  ' x ' ,  ' y ' ,  ' z ' ,  ' A ' ,  ' B ' ,  ' C ' ,  ' D ' ,  ' E ' ,  ' F ' ,  ' G ' ,  ' H '
,
10              ' I ' ,  ' J ' ,  ' K ' ,  ' L ' ,  ' M ' ,  ' N ' ,  ' O ' ,  ' P ' ,  ' Q ' ,  ' R ' ,  ' S ' ,  ' T ' ,  ' U '
,
11              ' V ' ,  ' W ' ,  ' X ' ,  ' Y ' ,  ' Z '  }
;
12

13      private   static  String genRandomString() 
{
14          for  ( int  i  =   0 , j  =   78 ; i  <   30 ;  ++ i,  -- j) 
{
15              int  take  =  ( int ) (Math.random()  *
 j);
16             rst[i]  =
 ch[take];
17              char  m  =  ch[j  -   1 ]; //  Move ch[take] to the back of

18             ch[j  -   1 ]  =  ch[take]; //  ch[]
19             ch[take]  =  m; //  and then j--
20         }

21          return   new  String(rst);
22     }

23
24     
/**
25      *  @param  args
26       */

27      public   static   void  main(String[] args)  {
28          for  ( int  i  =   0 ; i  <   40 ;  ++ i) 
{
29
            System.out.println(genRandomString());
30         }

31     }

32 }

posted on 2006-03-17 11:31 Apache's___Tomcat 阅读(186) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: