/**
*
* @param start
* @param end
* @return >= start && <=end 的随机数
* end需大于start 否则返回-1
*/
public static int getRandom(int start,int end){
if(start>end || start <0 || end <0){
return -1;
}
return (int)(Math.random()*(end-start+1))+start;
}
java取指定范围随机数
最新推荐文章于 2023-03-24 11:38:42 发布