EN
Java - get random float number
12
points
1. Generate random float with ThreadLocalRandom class
public static float nextFloat() {
return ThreadLocalRandom.current().nextFloat();
}
Example:
System.out.println(nextFloat()); // 0.5261965
System.out.println(nextFloat()); // 0.23931652
System.out.println(nextFloat()); // 0.8099988
2. Generate random float with Random class
public static float nextFloat2() {
return new Random().nextFloat();
}
Example:
System.out.println(nextFloat2()); // 0.0030902028
System.out.println(nextFloat2()); // 0.77623594
System.out.println(nextFloat2()); // 0.39141566