| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 14830 人关注过本帖
标题:c语言中如何产生任意范围的随机数?
取消只看楼主 加入收藏
指向指针的指针
Rank: 1
等 级:新手上路
帖 子:339
专家分:0
注 册:2004-8-8
收藏
 问题点数:0 回复次数:2 
c语言中如何产生任意范围的随机数?
c语言中如何产生任意范围的随机数?比如说0-100的整数;-100~100的整数;10~100的整数;34.23~56.98的两位小数等等?

/sign.png" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www./sign.png');}" onmousewheel="return imgzoom(this);" alt="" />
2004-08-23 18:53
指向指针的指针
Rank: 1
等 级:新手上路
帖 子:339
专家分:0
注 册:2004-8-8
收藏
得分:0 

迷糊了

我说的是产生指定范围的随机数,包括整数小数正数负数

比如说0-100的整数;-100~100的整数;10~100的整数;34.23~56.98的两位小数等等?


/sign.png" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www./sign.png');}" onmousewheel="return imgzoom(this);" alt="" />
2004-08-26 19:40
指向指针的指针
Rank: 1
等 级:新手上路
帖 子:339
专家分:0
注 册:2004-8-8
收藏
得分:0 
以下是引用阿一2004在2004-08-27 17:49:51的发言:

上面老兄要钱的东东,我买了,可是能力有限,又没有文这说明,

我得回家好好看看,下面为广大人民服务,公布我用五十元买来的好东东。嘻嘻,:

#include <stdlib.h> #include <stdio.h>

int main(void) { int i,t; double s; printf("Ten random numbers from 0 to 100\n\n"); for(i=0; i<100; i++) { if(!(i%10))getch(); printf("%d\n", rand() % 101); } printf("Ten random numbers from 10 to 100\n\n"); for(i=0; i<100; i++) { if(!(i%10))getch(); printf("%d\n", rand() % 90+10); } printf("Ten random numbers from -100 to 100\n\n"); for(i=0; i<100; i++) { if(!(i%10))getch(); t= rand() % 10>5?1:-1; printf("%d\n", (rand() % 101)*t); } printf("Ten random numbers from 35.68 to 55.68\n\n"); for(i=0; i<100; i++) { if(!(i%10))getch(); t = rand()%2000 + 3568; s = t/100f; printf("%lf\n", s); } }

为人民服务,不错,口头表扬一次


/sign.png" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www./sign.png');}" onmousewheel="return imgzoom(this);" alt="" />
2004-08-30 14:42
快速回复:c语言中如何产生任意范围的随机数?
数据加载中...
 
   



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

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