//Math.ramdom()方法的测试
public class RandomTestDemo
{
public static void main(String[] args)
{
final int SUBINTERVAlS = 100;
final int TOTAL = 50000;
int [] frequency = new int[SUBINTERVAlS ];
for(int k =0 ;k < SUBINTERVAlS ;k++)
frequency[k]=0;
for(int j = 0; j < TOTAL ;j++)
{
double x = Math.random();//0.0<x<1.0
x*=SUBINTERVAlS ;//0.0<x<100.0
x=Math.floor(x);//
long m = Math.round(x);
int k = (int)x;
++frequency[k];
}
for(int i = 0;i < SUBINTERVAlS ;i++)
{
System.out.print(frequency[i]+(i%10==9?"\n":" "));
}
}
}
Math.ramdom()方法的测试
最新推荐文章于 2024-02-24 03:19:00 发布