Random nextFloat() in Java

nextFloat(): This method is available in java.util.Random class of Java.

Syntax:

float java.util.Random.nextFloat()

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

Parameters: NA

Returns: the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence.

Exceptions: NA

Approach

Java

import java.util.Random;

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

        Random random = new Random();

        System.out.println(random.nextFloat());
    }
}

Output:

0.40463966


No comments:

Post a Comment