如果真是你说的那种情况,我估计是因为System.currentTimeMillis() 这个随机参数有问题,你先拭试不要参数吧,因为从循环外调用时每次的参数其实不一样,由于这个参数是连续的而不是随机的,故而影响随机效果。

解决方案 »

  1.   

    0.05 = 5/100 = 1/20long TIMES = 10000;
    Random rand = new Random(System.currentTimeMillis());
    int count = 0;
    for(int i = 0; i < TIMES; i++) {
       count += (Math.abs(rand.nextInt()) % 20) == 0) ? 1: 0;
    }
    System.out.println("times:"+count+"\t"+ ((float)count/TIMES));
      

  2.   

    Random rand = new Random(System.currentTimeMillis());
    seed is almost same if you call glTest() from outside.