Java API Tutorial - Java Random.nextFloat()








Syntax

Random.nextFloat() has the following syntax.

public float nextFloat()

Example

In the following code shows how to use Random.nextFloat() method.

/* w  ww  . j  a  v a 2  s.  co m*/
import java.util.Random;

public class Main {
   public static void main( String args[] ){

      Random randomno = new Random();
 
      // check next float value  
      System.out.println("Next float value: " + randomno.nextFloat());
   }      
}

The code above generates the following result.