#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N];
// Fisher-Yates洗牌算法
void shuffle(int n)
{
srand(time(NULL));
for (int i = n; i > 1; i--)
{
int j = rand() % i + 1;
swap(a[i], a[j]);
}
}
int main()
{
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) a[i] = i;
//调用函数
shuffle(n);
for (int i = 1; i <= n; i++)
printf("%d ", a[i]);
return 0;
}
标签:Yates,int,洗牌,个数,算法,Fisher
From: https://www.cnblogs.com/acwhr/p/17836690.html