---恢复内容开始---
1 public static String generateString(int length) // 参数为返回随机数的长度 2 { 3 StringBuffer sb = new StringBuffer(); 4 Random random = new Random(); 5 for (int i = 0; i < length; i++) { 6 sb.append(numberChar.charAt(random.nextInt(numberChar.length()))); 7 } 8 return sb.toString(); 9 }
---恢复内容结束---
String sixRandom =(int)((Math.random()*9+1)*100000)+"";
.deleteCharAt(length-1); //删除最后一个字符
/** * 随机产生n个10以内的数字字符串 * @param n * @return */ public static String random(int n){ if(n <= 0) return ""; StringBuilder builder = new StringBuilder(); for(int i=0;i<n;i++) { int number = new Random().nextInt(10); builder.append(number); } return builder.toString(); }