使用Random生成随机的float,范围[0,1)
float b = new Random().nextFloat();
测试用例
public class TestRandom {
public static void main(String[] args) {
Random random = new Random();
for (int i = 0; i < 100; i++) {
System.out.println(random.nextFloat());
}
}
}
输出结果
0.4941969
0.53911686
0.4846254
......
0.10841596
0.029320478
0.52353495
......