nextfloat
隨機類nextFloat()方法 (Random Class nextFloat() method)
nextFloat() method is available in java.util package.
nextFloat()方法在java.util包中可用。
nextFloat() method is used to generate the next pseudo-random float value between the range 0.0 and 1.0 from this Random Value Generator.
nextFloat()方法用于從該隨機值生成器生成介于0.0和1.0之間的下一個偽隨機浮點值。
nextFloat() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
nextFloat()方法是一個非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。
nextFloat() method does not throw an exception at the time of returning float.
返回float時, nextFloat()方法不會引發異常。
Syntax:
句法:
public float nextFloat();
Parameter(s):
參數:
It does not accept any parameter.
它不接受任何參數。
Return value:
返回值:
The return type of the method is float, it returns next pseudo-random distributed float value between the given range from this Random Generator.
方法的返回類型為float ,它從該Random Generator返回給定范圍之間的下一個偽隨機分布float值。
Example:
例:
// Java program to demonstrate the example
// of float nextFloat() method of
// Random
import java.util.*;
public class NextFloatOfRandom {
public static void main(String args[]) {
// Instantiates Random object
Random ran = new Random();
// By using nextFloat() method is
// to return float pseudo-random
// value between 0.0 and 1.0 by
// using Random Value Generator
float val = ran.nextFloat();
// Display
System.out.println("ran.nextFloat(): " + val);
}
}
Output
輸出量
RUN 1:
ran.nextFloat(): 0.89347947
RUN 2:
ran.nextFloat(): 0.48533785
RUN 3:
ran.nextFloat(): 0.2989604
翻譯自: https://www.includehelp.com/java/random-nextfloat-method-with-example.aspx
nextfloat