#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
using namespace std;
int main() {//rand, time随机函数的用法
while (1) {
Sleep(1000);
srand(time(0));//随机种子 time(0)返回时间值
int r = rand() % 100 + 1;//随机输出一个0到100内得数
printf("%d\n", r);
}
return 0;
}
c语言rand,srand用法
最新推荐文章于 2025-10-30 23:18:39 发布
本文介绍了一个使用C++生成随机数的简单程序。该程序利用了C++标准库中的函数,结合Windows下的Sleep函数实现每秒更新一次随机数的效果,并展示了如何使用time作为随机数生成器的种子。
3917

被折叠的 条评论
为什么被折叠?



