Code:
#include<cstdio>
#include<algorithm>
#include<ctime>
#include<cstdlib>
using namespace std;
const int maxn = 2000;
int arr[maxn];
int random(int n){ return (long long) rand() * rand() % n; } //生成一个 0 ~ n 的随机数
int main()
{
srand((unsigned) time(0)); //随机数种子
}
本文介绍了一种使用C++生成随机数的方法,并通过srand和time函数进行随机数种子的初始化,确保每次运行程序时都能得到不同的随机数序列。
2098

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



