random_shuffle() 随机化函数
STL中的函数random_shuffle()用来对一个元素序列进行重新排序(随机的)
srand(time(0)); 这个是设置时间种子,加了这句才能保证每次都是随机的,不然就不太随机。
#include<bits/stdc++.h>
using namespace std;
int main()
{
srand(time(0));
int a[5] = {5,2,2,4,1};
random_shuffle(a,a+5);
for ( int i=0; i<5; i++ ) cout << a[i] ;
return 0;
}