I've searched the web for some ways to make random strings be created, and the only thing I could find was to produce a random letter from a string "ABC..etc".
However, I cannot find an answer for my situation. I want to start with a list/array/vector of color strings, and have 6 of them be displayed in a random order. This is a snippet of the beginning of the code I currently have:
1 2 3 4 5 6
|
string colors[] = {"Red", "Orange", "Yellow", "Green", "Blue", "Violet", "White", "Gray", "Black", "Brown"};
const int NUMBER_OF_COLORS = 6;
for ( int color_index = 0; color_index < NUMBER_OF_COLORS; color_index++ )
{
cout << " " << colors[color_index] << " Worm" << endl;
}
|
Basically, what I want is this: Instead of having the list always start at Red, then Orange, etc, until Violet, I want it to display 6 random colors from the list.
Example output:
1 2 3 4 5 6
|
Gray Worm
Red Worm
Green Worm
Blue Worm
Black Worm
White Worm
|
I am using the C++11
random_device number generator, but if you want to use another random generator to show me, that's fine.
I also have a question or two about assigning number values that can change randomly to each string value produced, but I'll save that for another thread once I have a single objective for that.