java随机数的生成

我们经常会用到随机数的生成,作为唯一性的id或者标识:

long now = System.currentTimeMillis();
SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy");
String time=dateFormat.format(now);
String info=now+"";
int ran=(int) ((Math.random()*9+1)*100);

return  time+info.substring(2, info.length())+ranl;

在此记录好,以便下次使用

原文地址:https://www.cnblogs.com/hackxiyu/p/8760333.html