zoukankan      html  css  js  c++  java
  • java--随机数的产生

    随机数产生的三种方法:

    1、system.currentTimeMillis()

    public class Demo1{
        public static void main(String[] args) {
            System.out.println(System.currentTimeMillis());
        }
    }

    显示的时间是从1970年1月1日开始到目前的时间的毫秒数;

    2、math.random()

    将会产生0.0--1.0之间的随机数

    API :   java.lang.Math

    3、Random()

    public class Demo1{
        public static void main(String[] args) {
            double r1 = Math.random();
            System.out.println(r1);
            
            Random r2 = new Random(System.currentTimeMillis());
            Random r3 = new Random(System.currentTimeMillis());
            int res1 = r2.nextInt(10);
            
            int res = r2.nextInt(10);
            System.out.println(res);
            System.out.println(res1);
        }
    }
  • 相关阅读:
    Mac配置docker阿里云加速器
    Docker初学笔记
    Mac下载安装Tomcat
    MySQL
    monkey
    Git基本使用
    yaml语法
    PAT_B数素数 (20)
    PAT_B1002数字分类
    PAT基础编程练习
  • 原文地址:https://www.cnblogs.com/plxx/p/3346642.html
Copyright © 2011-2022 走看看