温习一下

   public static void main(String[] args) {
        //  加种子后 ,随机数就定了(每次随机都是这个数)
        Random rm=new Random();
        for (int i = 0; i <10 ; i++) {
             //  10 代表从哪开始  20 是随机数  0-19
            //  随机数的范围 10~29
            System.out.print(10+rm.nextInt(20)+"\t");
        }

        for (int i = 0; i <1000000 ; i++) {
            //  100000 代表从哪开始  900000 是随机数  0-899999
            //  随机数的范围 100000~999999
            System.out.print(100000+rm.nextInt(900000)+"\t");
        }
}

Math方法
//返回指定范围的随机数(m-n之间)的公式
Math.random()*(n+1-m)+m

public static void main(String[] args) {
        for (int i = 0; i <10 ; i++) {
            //    10~19
            System.out.println((int)(Math.random() *10)+10);
           // 10~ 999

            System.out.println((int)(Math.random() *990)+10);
        }
    }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2021-05-29
  • 2021-09-01
  • 2022-02-10
猜你喜欢
  • 2021-11-30
  • 2022-01-06
  • 2021-11-05
  • 2022-01-24
相关资源
相似解决方案