Random 随机生成数

package Baozhuang;

import java.util.Random;

public class RandomTest {
    public static void main(String[] args) {
        /*Random random = new Random();
        int i = random.nextInt(10);
        System.out.println(i);
        
        //在 0.0 和 1.0 之间均匀分布的 float,double 值。
        float f = random.nextFloat();
        System.out.println(f);
        double d = random.nextDouble();
        System.out.println(d);
        boolean b = random.nextBoolean();
        System.out.println(b);*/
        Random random = new Random();
        for(int i = 0; i<10 ; i++){
            double d = random.nextDouble()*9+1;
            /*double d = Math.random()*9+1;*/
            System.out.println(d+" ");
        }
        int i = 0;
        int j = 0;
        for(i = 0 ; i < 10 ;i++){
            boolean b = random.nextBoolean();
            System.out.println(b+" ");
            if(b){
                j++;
            }
        }
        System.out.println("true占比例:"+(double)j/i);
        
        int i1 = random.nextInt(89)+10;
        System.out.println(i1);
    }
}

 

posted @ 2016-08-11 17:37  me丶不是好人  阅读(113)  评论(0编辑  收藏  举报