/** * 生成固定位数的随机数 * * @param length 随机数长度 * @return string */ private static String getRandom(int length) { char[] chars = new char[length]; for (int i = 0; i < length; i++) { chars[i] = '0'; } String patten = new String(chars); int randomBase = Integer.valueOf("1" + patten); int rand = (int) (Math.random() * randomBase); DecimalFormat decimalFormat = new DecimalFormat(patten); return decimalFormat.format(rand); }
@Test /** * 生成0-1之间的随机数 * */ public void tset(){ double random = Math.random(); System.out.println(random); }