random
public static double random()
Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. Returned values are chosen pseudorandomly with (approximately) uniform distribution from that range.
When this method is first called, it creates a single new pseudorandom-number generator, exactly as if by the expression new java.util.Random
This new pseudorandom-number generator is used thereafter for all calls to this method and is used nowhere else.
This method is properly synchronized to allow correct use by more than one thread. However, if many threads need to generate pseudorandom numbers at a great rate, it may reduce contention for each thread to have its own pseudorandom-number generator.
Returns:
a pseudorandom double greater than or equal to 0.0 and less than 1.0.
See Also:
Random.nextDouble()
用他产生一个0-1的数,再*1000就成了一个四位的,可能还要取一下整吧!
public static double random()
Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. Returned values are chosen pseudorandomly with (approximately) uniform distribution from that range.
When this method is first called, it creates a single new pseudorandom-number generator, exactly as if by the expression new java.util.Random
This new pseudorandom-number generator is used thereafter for all calls to this method and is used nowhere else.
This method is properly synchronized to allow correct use by more than one thread. However, if many threads need to generate pseudorandom numbers at a great rate, it may reduce contention for each thread to have its own pseudorandom-number generator.
Returns:
a pseudorandom double greater than or equal to 0.0 and less than 1.0.
See Also:
Random.nextDouble()
用他产生一个0-1的数,再*1000就成了一个四位的,可能还要取一下整吧!
解决方案 »
- 大家帮我看看这个java链表问题出在哪?
- Method类中的invoke()方法?
- 调用windows下的cmd指令运行.class文件
- Iteration abstraction, Data abstraction, Procedural abstraction, Type abstraction definitions
- 有偿转让Java即时通信工具源程序及设计文档
- 全半角转换问题,万分感谢,需要源代码。
- 在线等 panel清空后再添加控件为什么添加不上
- 求助!java有没有对powerpoint进行操作的API?
- 请JFC的大侠指点
- 希望得到:一位CSDN论坛的高手:“levelmini”的“个人信息”:手机号码.工作单位.并且希望能够成为Levelmini一辈子的,好朋友!!
- 请教一个菜鸟问题:将一个对象引用设置为NULL时......
- 日本政府太可恶,倡议抵制日货!!!
String fourRandom = "";
int randomNum = (int)(Math.random()*10000);
fourRandom = "" + randomNum;
int randLength = fourRandom.length();
if(randLength<4){
for(int i=1; i<=4-randLength; i++)
fourRandom = "0" + fourRandom;
}else{
fourRandom = "" + randomNum;
}
return fourRandom;
}