- public static final String numberChar = "0123456789";
- /**
- * 根据系统时间获得指定位数的随机数
- *
- * @return 获得的随机数
- */
- public static String getRandom() {
- Long seed = System.currentTimeMillis();// 获得系统时间,作为生成随机数的种子
- StringBuffer sb = new StringBuffer();// 装载生成的随机数
- Random random = new Random(seed);// 调用种子生成随机数
- for (int i = 0; i < 20; i++) {
- sb.append(numberChar.charAt(random.nextInt(numberChar.length())));
- }
- return sb.toString();
- }
- //该片段来自于http://www.codesnippet.cn/detail/130620149762.html
来源: http://www.codesnippet.cn/detail/130620149762.html