/** * 返回長度為【strLength】的隨機數,在前面補0 * @param strLength 長度 * @return 隨機數 */ public static String getFixLengthString(int strLength) { Random rm = new Random(); // 獲得隨機數 double pross = (1 + rm.nextDouble()) * Math.pow(10, strLength); // 將獲得的獲得隨機數轉化為字符串 String fixLengthString = String.valueOf(pross); // 返回固定的長度的隨機數 return fixLengthString.substring(1, strLength + 1); }