| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 677 人关注过本帖
标题:[求助],随机数问题!!!
只看楼主 加入收藏
tqtbj
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2004-8-1
收藏
 问题点数:0 回复次数:5 
[求助],随机数问题!!!

int n=(int)(Math.random()*m) 如果m=1000000时,这时n 的范围为多大呀? 它可能产生 7 吗 ?

(int)(Math.random())产生的范围是不是[0,1)之间呀?

搜索更多相关主题的帖子: 随机数 
2004-08-12 13:29
Anstey
Rank: 1
等 级:新手上路
帖 子:94
专家分:0
注 册:2004-4-14
收藏
得分:0 

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


Anstey. Cheers. I love CAPPUCCINO~~
2004-08-12 20:49
tqtbj
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2004-8-1
收藏
得分:0 

谢谢老大了

2004-08-17 00:10
lyn_gemini
Rank: 1
等 级:新手上路
帖 子:103
专家分:3
注 册:2004-9-15
收藏
得分:0 

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)


欢迎访问我的博客--*IT一粟*-- : http://lyn_gemini.
2004-09-16 13:48
shanji
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2005-1-23
收藏
得分:0 
2005-04-05 21:00
zengyu222
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-10-31
收藏
得分:0 
学习了。
2006-11-05 17:22
快速回复:[求助],随机数问题!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019399 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved