package com.henu;
import java.util.Random;
public class Test05 {
public static void main(String[] args) {
//Math方法 x即为[20,30]的整数。
int x = (int)(20+Math.random()*11);
//Random方法 y即为[20-30]的整数
Random r = new Random();
int y = 20 + (r.nextInt(11));
}
}
假设取【m,n】m<n;的随机整数 则
Math.random的规律是:
(int)(m+Math.random()*(n-m+1));
Random类的规律是:
m+(new.Random()).nextInt(n-m+1);