写了如下工具类:
public class SystemUtil { public static String getRandomNumberByNum(int num) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < num; i++) { long randomNum = Math.round(Math.floor(Math.random() * 10.0D)); sb.append(randomNum); } return sb.toString(); } }
以生成10位随机数为例:
public class Producer { public static String generateIdOfTen() { String randomNumber = SystemUtil.getRandomNumberByNum(10); long time = System.currentTimeMillis(); return time + randomNumber; } }
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/10813.html