Math-random方法

Math.random()默认产生大于等于0.0且小于1.0之间的随机double型随机数
 1 package com.shuzu;
 2 //import 导入包关键字  使用java.long包中的内容的时候不需要导入
 3 
 4 public class Test6 {
 5 
 6     public static void main(String[] args) {
 7         //Math.random();随机数的产生
 8         double su = Math.random();//[0,1)之间的随机数 double型
 9         int num = (int)(Math.random()*(9+1));//产生[0,9]之间的随机数 int型
10         num = (int)(Math.random()*(99+1));//产生[0,99]之间的随机数 int型
11         num = (int)(Math.random()*(999+1));//产生[0,999]之间的随机数 int型
12         num = (int)(Math.random()*(3+1));//产生[0,3]之间的随机数 int型
13         //num = (int)(Math.random()*(a+1));//产生[0,a]之间的随机数 int型
14         num = (int)(Math.random()*((20-10)+1)+10);//产生[10,20]之间的随机数 int型
15         num = (int)(Math.random()*((13-6)+1)+6);//产生[6,13]之间的随机数 int型
16         int max=555;
17         int min=222;
18         for(int i=0;i<300;i++) {
19             num = (int)(Math.random()*((max-min)+1)+min);//产生[min,max]之间的随机数 
20             System.out.println(num);
21         }
22     }
23 
24 }
原文地址:https://www.cnblogs.com/d-java/p/13068930.html