c语言的随机函数在TC和VC中是什么呀?

hewei1999 2004-12-24 10:51:49
c语言的随机函数在TC中好像是random(),在VC中好像是rand()是吗 在头文件中写什么呀?在函数中怎么用呀 !高手请教??????
...全文
101 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jin_xiaolu2000 2004-12-24
  • 打赏
  • 举报
回复
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main(void)
{
randomize();
printf("Random number in the 0-99 range: %d
", random (100));
return 0;
}

c中的random
srand( (unsigned)time( NULL ) );产生种子,然后使用rand()
random()会自动调GetTickCount()得到一个数
snow810211 2004-12-24
  • 打赏
  • 举报
回复
rand <stdlib.h>
Example
/* RAND.C: This program seeds the random-number generator
* with the time, then displays 10 random integers.
*/

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

void main( void )
{
int i;

/* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
srand( (unsigned)time( NULL ) );

/* Display 10 numbers. */
for( i = 0; i < 10;i++ )
printf( " %6d\n", rand() );
}

Output
6929
8026
21987
30734
20587
6699
22034
25051
7988
10104

JerrySabrina 2004-12-24
  • 打赏
  • 举报
回复
Routine Required Header
rand <stdlib.h>

70,021

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧