java-随机数

Math.random() 返回一个0到1之间(包括0,不包括1)的随机浮点数;

用n乘以这个随机浮点数,可以得到0到n-1之间的随机数;

double a =  Math.random(); // 0.4921534576132002
int b = (int) (Math.random() * 10);
System.out.println(b);// 5
原文地址:https://www.cnblogs.com/My-Cloud/p/4597618.html