生出随机数

来源:互联网 发布:ubuntu 访问移动硬盘 编辑:程序博客网 时间:2024/05/01 22:56
import java.util.Random; /** * This example explains how to generate random numbers and values. */public class RandomNumberGenerator {    public RandomNumberGenerator() {        super();    }     public static void main(String[] args) {        Random rand = new Random();         //Random Integer from 0(inclusive) to 100(exclusive)        System.out.println("First Random Integrer value : " +                           rand.nextInt(100));        //Generate anothor randon number.        System.out.println("Generate Second Random Integrer value : " +                           rand.nextInt(500));         System.out.println("Generate Random Float value : " +                           rand.nextFloat());         System.out.println("Generate Random Double vale : " +                           rand.nextDouble());         System.out.println("Generate Random Boolean value : " +                           rand.nextBoolean());    }}
注意第27行随机生成真假之一
原创粉丝点击