请问C语言的随机函数是什么?

liuleimilk 2005-10-27 10:32:58
请问C语言的随机函数是什么?
...全文
104 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
iwantfat 2005-10-27
  • 打赏
  • 举报
回复
rand();
codearts 2005-10-27
  • 打赏
  • 举报
回复
#include <stdlib.h>
#include <stdio.h>

int main(void)
{
int i;

randomize(); //初始化种子
printf("Ten random numbers from 0 to 99\n\n");
for(i=0; i<10; i++)
printf("%d\n", rand() % 100);
return 0;
}
v41dugu 2005-10-27
  • 打赏
  • 举报
回复
srand()能产生种子
v41dugu 2005-10-27
  • 打赏
  • 举报
回复
rand();没参数
xuzheng318 2005-10-27
  • 打赏
  • 举报
回复
#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
liuleimilk 2005-10-27
  • 打赏
  • 举报
回复
有什么格式的吗?
睡在床板下_ 2005-10-27
  • 打赏
  • 举报
回复
rand()

69,380

社区成员

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

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