class="java" name="code"> /** * 获取随机数4位 * @return */ public static String getRandomNumber(){ StringBuffer buffer = new StringBuffer(); for(int i = 0; i < 4; i++){ int num = (int) (Math.random() * 10); buffer.append(num); } return buffer.toString(); }