randomizing array with strings and appearing only once

I'm completely stumped. I can initialize my array and randomize it using the names that I have in my array, but I cannot error check it so that it appears only once in the array. Therefore the names becomes duplicates which I'm not supposed to have. Any help would be appreciated. Here's my code:
///////////////CODE////////////////////////////////////////////
string NameArray[5] = {"KillerJohn" , "GerNater" , "DemonJosh","CyborgEmily", "SuperJoe"};

cout<< "Before the Name Random\n";

for (int i =0; i <=4; i++)
{
cout << NameArray[i] << endl;
}
cout << endl;
cout <<"After the randomizing\n";

srand(time(0));

for (int j =0; j<=4; j++)
{
string Random;
Random = NameArray[rand()%5];
cout << Random << endl;
NameArray[j] = Random ;
}
/////////////////END////////////////////
This code is in a class assuming I have all the common libraries.
Scan through the algorithms in the reference section. You will probably find a std algorithm in the standard library that does exactly what you want.
Thanks Pan That solved my Problem. Part of this C++ is that I don't know the codes to use aka a "noob programmer".

Basically you have to use the random_shuffle function for the array to randomize it.
Last edited on
Topic archived. No new replies allowed.