java.util.Random.nextFloat() Method



Description

The nextFloat() method is used to get the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence.

Declaration

Following is the declaration for java.util.Random.nextFloat() method.

public float nextFloat()

Parameters

NA

Return Value

The method call returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence.

Exception

NA

Example

The following example shows the usage of java.util.Random.nextFloat()

package com.tutorialspoint;

import java.util.*;

public class RandomDemo {
   public static void main( String args[] ) {
      
      // create random object
      Random randomno = new Random();
    
      // check next float value  
      System.out.println("Next float value: " + randomno.nextFloat());
   }      
}

Let us compile and run the above program, this will produce the following result.

Next float value: 0.5909014
java_util_random.htm
Advertisements