日期:2014-05-20 浏览次数:20810 次
public static String getRandomString(int length) { length = length < 0 ? -length : length; char[] chs = new char[length]; Random ran = new Random(); for(int i = 0; i < chs.length; i++) { chs[i] = (char)(ran.nextInt(10) + '0'); } return new String(chs); }
------解决方案--------------------
/** * 返回一个随机数 * * @param i * @return 一个随机数 */ public static String getRandom(int i) { Random random = new Random(); // int suiJiShu = jjj.nextInt(9); if (i == 0) { return ""; } String strRandom = ""; for (int k = 0; k < i; k++) { strRandom = strRandom + random.nextInt(9); } return strRandom; }