Hello, I am making a "High Scores" Program from Chapter 4 of Michael Dawson's Introduction To C++ Through Game Programming Book (3rd Edition). In it, a vector consisting of 3 numbers is made and multiple manipulations are made to it through Standard Library Algorithms. There is a situation where the vector's contents have to be randomized and placed in random order, but after the manipulation, their position dosn't seem to change. The code is below:
`
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
vector<int>::const_iterator iter;
cout << "Creating a list of scores.";
vector<int> scores;
scores.push_back(1500);
scores.push_back(3500);
scores.push_back(7500);
cout << "\nHigh Scores:\n";
for (iter = scores.begin(); iter != scores.end(); ++iter)
cout << *iter << endl;
cout << "\nFinding a score.";
int score;
cout << "\nEnter a score to find: ";
cin >> score;
iter = find(scores.begin(), scores.end(), score);
if (iter != scores.end())
cout << "Score found.\n";
else
cout << "Score not found.\n";
cout << "\nRandomizing scores.";
srand(static_cast<unsigned int>(time(0)));
random_shuffle(scores.begin(), scores.end());
cout << "\nHigh Scores:\n";
for (iter=scores.begin();iter!=scores.end();++iter)
{
cout << *iter<< endl;
}
cout << "\nSorting scores.";
sort(scores.begin(), scores.end());
cout << "\nHigh Scores:\n";
for (iter = scores.begin(); iter != scores.end(); ++iter)
cout << *iter << endl;
return 0;
}
`
My Result From The Output Window Is Below:
`
Creating a list of scores.
High Scores:
1500
3500
7500
Finding a score.
Enter a score to find: 355
Score not found.
Randomizing scores.
High Scores:
1500
3500
7500
`
As you can see, after the program "randomly changes the position of the vector's contents," the numbers still remain in order. I have tried seeding my generator with different methods (including the method that is in Michael Dawson's online downloadable code, which BTW, is different than the one that he used in his book). However, I kept getting the same result. Can anybody offer a new perspective on what is going on?