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
----------------解决方案--------------------------------------------------------
谢谢老大了
----------------解决方案--------------------------------------------------------
there is a class about random : java.util.Random
you can use it as this : Random rd = new Random();
rd.nextInt(int ceil);
then it will generate a value form 0 to ceil-1.(including 0 and ceil)
----------------解决方案--------------------------------------------------------
----------------解决方案--------------------------------------------------------
学习了。
----------------解决方案--------------------------------------------------------