static double random()
描述 (Description)
java.lang.StrictMath.random()方法返回一个带有正号的double值,大于或等于0.0且小于1.0。此方法已正确同步,以允许多个线程正确使用。
声明 (Declaration)
以下是java.lang.StrictMath.random()方法的声明
public static double random()
参数 (Parameters)
NA
返回值 (Return Value)
此方法返回大于或等于0.0且小于1.0的伪随机double。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.lang.StrictMath.random()方法的用法。
package com.iowiki;
import java.lang.*;
public class StrictMathDemo {
public static void main(String[] args) {
/* returns a double value with a positive sign,
greater than or equal to 0.0 and less than 1.0 */
double randomValue = StrictMath.random();
System.out.println("1st randomly generated number = "+ randomValue);
System.out.println("2nd randomly generated number = "+ StrictMath.random());
System.out.println("3rd randomly generated number = "+ StrictMath.random());
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
1st randomly generated number = 0.9920868657769093
2nd randomly generated number = 0.15952532993970858
3rd randomly generated number = 0.26097639244001813