你好,我想请问c语言编写随机产生一百个整数的原理或者伪代码是什么?第一次接触过。 - 爱问答

(爱问答)

你好,我想请问c语言编写随机产生一百个整数的原理或者伪代码是什么?第一次接触过。

rand()函数原型

int rand(void);

功能

rand uses a multiplicative congruential random number generator with period 2 to the 32nd power to return successive pseudo-random numbers in the range from 0 to RAND_MAX. The symbolic constant RAND_MAX is defined in stdlib.h.

例子

 

#include <stdlib.h>

#include <stdio.h>

#include <time.h>

 

int main(void)

{

   int i;

   time_t t;

 

   srand((unsigned) time(&t)); //初始化随机数种子,没有这个,每次运行的随机数会相同的 

   printf("Ten random numbers from 0 to 99 ");

   for(i=0; i<10; i++)

       printf("%d ", rand() % 100); //生成0~99的随机数 

   return 0;

}


相关标签:c语言

下一篇:请问电脑怎么为什么这么卡,怎么解决?

上一篇:温度传感器怎么接PLC?

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?