用nextInt()就可以了,不用加参数。
不过一般不用这种方法,产生一般的随机树用Math.random(),随机整数用Math.random()*a+b得到a到b间的随机数.
不过一般不用这种方法,产生一般的随机树用Math.random(),随机整数用Math.random()*a+b得到a到b间的随机数.
解决方案 »
- 求JAVA程序编写的MVC+Jquery实现增删改查以及分页的小项目!
- hibernate结合oracle11g 报这个错……
- 关于war包发布的问题
- 导出到EXECL出错,请各位高手帮我看看是什么错误,非常感谢!!!
- hibernate 数据库保存异常
- Dbutils中的QueryRunner()为什么有的时候不需要传递connection对象也能使用?
- 为了大家更好的交流,我已经给大家提供了ftp服务器,希望大家都能把自己的msn留下,以便更好的交流!
- 求助:关于tomcat的javaBean问题
- 怎么在jsp中调用一般的class
- 关于jsp include
- 有的网址后面没有扩展名。是怎么回事。请帮
- jsp中如何取得text的值????????????
import java.util.*;/**
* Title: TestOnline
* Description:
* Copyright: Copyright (c) 2003
* Company: NSI
* @author junzhang.li
* @version 1.0
*/public class Stochastic { public Stochastic() {
}
public int number(int n){
Random rand=new Random();
int i=rand.nextInt();
i%=n;
while(i==0)
{
i=rand.nextInt();
i%=n;
}
if(i<0)
i=-i;
return(i);
}
//--------------------ヨ篌ッハ
/*public static void main(String[] args) {
Stochastic stochastic1 = new Stochastic();
int p=stochastic1.number(10);
System.out.print(p);
}*/
//---------------------
}
这是我以前做的,测试通过
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class randomBean { public randomBean() {
}
private int[] getRandom(int ipar){
Random m=new Random();
int ri[]=new int[7];
for(int i=0;i<7;i++){
ri[i]=m.nextInt(ipar); } return ri;
}
public int[] returnRandom(){ int[] iArray=getRandom(36);
int iSize=iArray.length;
for(int i=0;i<iSize;i++){
for(int j=i+1;j<iSize;j++){
if(iArray[i]==iArray[j]){
iArray=returnRandom(); return iArray;
}else if(iArray[i]==0 || iArray[j]==0){
iArray=returnRandom();
return iArray;
}
}
}
return iArray;
}}