</pre><pre name="code" class="java">public class StringUtils{ private static Random randGen = new Random(); private static char[] letters =("0123456789abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray(); //获取指定长度的随机字符串 public static String randomString(int len){ if(len<1){ return null; } char[] buf= new char[len]; for(int i=0;i<len;i++){ buf[i]=letters[randGen.nextInt(71)]; } return new String(buf); } // }
posted on 2011-11-03 20:28 心笑峰 阅读(202) 评论(0) 编辑 收藏 举报