Java random() 方法

Java 教程 · 2019-02-08 16:29:33

random() 方法用于返回一个随机数,随机数范围为 0.0 =< Math.random < 1.0。

语法

static double random()

参数

  • 这是一个默认方法,不接受任何参数。

返回值

该方法返回 double 值。

实例

public class Test{
    public static void main(String args[]){
        System.out.println( Math.random() );
        System.out.println( Math.random() );
    }
}

编译以上程序,输出结果为:

0.5444085967267008
0.7960235983184115

点击查看所有 Java 教程 文章: https://www.codercto.com/courses/l/12.html

查看所有标签

Java Concurrency in Practice

Java Concurrency in Practice

Brian Goetz、Tim Peierls、Joshua Bloch、Joseph Bowbeer、David Holmes、Doug Lea / Addison-Wesley Professional / 2006-5-19 / USD 59.99

This book covers: Basic concepts of concurrency and thread safety Techniques for building and composing thread-safe classes Using the concurrency building blocks in java.util.concurrent Pe......一起来看看 《Java Concurrency in Practice》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码