java产生随机数(Math.random())

直接上代码------------------------java------------------------Math.random()

 1 import java.util.Scanner;
 2 
 3 public class Random {
 4 
 5     public static void main(String[] args) {
 6         int n;
 7         Scanner cin = new Scanner(System.in);
 8         System.out.println("请输入要产生的随机数的个数");
 9         n = cin.nextInt();
10         int[] a = new int[n];
11 
12         for (int i = 0; i < n; i++) {
13             a[i] = (int) (100 * Math.random());
14         }
15         /*
16          * 这的int可换为byte,但不能为float,long,double
17          * 其中的100产生随机数的范围为0~100内当然也可与为10,1000,1,任意数;
18          */
19 
20         for (int i = 0; i < n; i++) {
21             System.out.println("i = " + i + " " + a[i]);
22         }
23     }
24 
25 }
View Code
原文地址:https://www.cnblogs.com/sxmcACM/p/3444269.html