1、通过system.currenttimemillis()来获取一个当前时间毫秒数的long型数字。
long a = system.currenttimemillis(); system.out.println(a);
2、通过math.random()返回一个0到1之间的double值。
int b = (int)(math.random()*99+1); system.out.println(b);
3、通过random类来产生一个随机数。
random random = new random(); int c = random.nextint(100)+1; system.out.println(c);
【相关推荐】
1. java免费视频教程
2. 极客学院java视频教程
3. 阿里巴巴java开发手册
以上就是分享三个生成随机数的java代码教程的详细内容。