Ranbom类的主要成员方法:
public boolean nextBoolean().//随机生成boolean值 public double nextDouble().//随机生成【0,1】的double值 public float nextFloat().//随机生成【0,1】的flaot值 public int nextInt().//随机生成int值 public int nextInt(int n).//随机生成不大于n的int值 public long nextLong().//随机生成long值
package store.coffer;
import java.util.Random;
public class Ranbom2 {
public static void main(String[] args) {
Random random = new Random();
System.out.println(random.nextFloat());
System.out.println(random.nextDouble());
for(int i=0;i<5;i++){
System.out.println(random.nextInt(20)+"\t");
}
}
}