c++ランダム抽出コード


#include 
#include 
#include  
#include  
#include  
#include  

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector  number(n, 0);
	vector  person = {"aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii"};

	srand((unsigned)time(NULL));
	for (int i = 0; i < n; i++)
		number[i] = rand();

	for (int i = 0; i < n-1; i++)
	{
		for (int j = i+1; j < n; j++)
		{
			if (number[i] < number[j])
			{
				int tempInt = number[i];
				number[i] = number[j];
				number[j] = tempInt;
				string tempString = person[i];
				person[i] = person[j];
				person[j] = tempString;
			}
		}
	}

	cout << "          :" << endl;
	for (int i = 0; i < person.size(); i++)
		cout << i+1 << ": " << person[i] << "   " << endl;
	cout << endl << endl;

	int next;     //     ,   
	srand((unsigned)time(NULL));
	while (cin >> next)
	{
		next = rand() % n;
		cout << "  : " << next + 1 << endl;
		cout << "  : " << person[next] << endl << endl;
	}

	system("pause");
}