[求助],随机数问题!!!
int n=(int)(Math.random()*m) 如果m=1000000时,这时n 的范围为多大呀? 它可能产生 7 吗 ?
(int)(Math.random())产生的范围是不是[0,1)之间呀?
There is a gerneral formular to do this, say if we want the interval between a and b(inclusive,b>a), then
int i = (int)(Math.random()*(b-a+1)+a);
more general, we have
int ranNum = (int)(Math.random()*(upperBound-lowerBound+1)+lowerBound);
in the example above, this range should be 0<= n < 1000000, another word 0<= n <= 999999