概率和随机数的问题,高手帮帮忙,谢谢! 如果真是你说的那种情况,我估计是因为System.currentTimeMillis() 这个随机参数有问题,你先拭试不要参数吧,因为从循环外调用时每次的参数其实不一样,由于这个参数是连续的而不是随机的,故而影响随机效果。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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)); Random rand = new Random(System.currentTimeMillis());seed is almost same if you call glTest() from outside. 谁会GUI编程啊?求教 web应用怎样设置并使用cookie?? java.lang.NullPointerException 一个小程序,大家帮助分析一下,谢谢大家。 动态覆盖类的方法;请指教! 请问有谁知道如何读取硬盘分区序列号 请问java怎样调用一个外部程序,并得到这个外部程序的返回值,这哥外部程序不是java写的 求教关于Image的问题 java套接字编程 vector为什么不可以声明数组吗? 请问哪里有用JAVA实现语音聊天的例子或代码参考? 如何消除2个button中间的距离
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));
seed is almost same if you call glTest() from outside.