Get Random float type number in Java
Description
The following code shows how to get Random float type number.
Example
/*w w w .j av a 2 s.c o m*/
import java.util.Random;
public class Main {
public static void main(String[] argv) throws Exception {
Random rand = new Random();
float f = rand.nextFloat(); // 0.0 <= f < 1.0
System.out.println(f);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »