写了如下工具类:
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;
}
}