Java 实现在固定区间内随机生成整数

1、random.nextInt(num)  

public static void main(String args[]) {
    Random  rdom = new Random();
    int max = 1314;
    int min = 520;
    for(int i = 0;i<2000;i++){
        int count = rdom.nextInt((max - min + 1)) + min;
        if(count==1313){
            System.out.println("1313=================>>>"+count);
        }else if (count==520){
            System.out.println("520=================>>>"+count);
        }else if(count<520 || count>1313){
            System.out.println("error=================>>>"+count);
        }else{
            System.out.println("success=================>>>"+count);
        }
    }
}

  

posted @ 2019-11-11 14:57  活出自己范儿  Views(866)  Comments(0Edit  收藏  举报