How to Prevent Repeating Random Arrays?

I'm writing a program that will display a random string of array, but it would likely repeating the chosen array for a short time.
Ex.
Program: two
user: odd
Program: Right.
         two

.............sometimes the same string will appear for about 2-3 times before choosing another different array.

I want the program to choose a string once and never repeat the chosen string again. If the parameters are all already chosen, then it must terminate. Can you help me how to do this? Thanks.
ps:
can you just edit my code, chances are I can't understand enough what you'll explain :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 #include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;

int main ()
{
  while (true)
  {
  static string numbers[] = {"one", "two", "three","four","five","six","seven","eight","nine","ten"};
  srand(time(0));
  int rand_index = rand() % 10;
  cout << numbers[rand_index] << endl;

  string input;
  getline(cin,input);
  cout << (((input=="vector")==(rand_index+1)%2==0) ? "Right." : "Wrong.") << endl << endl;
}
}
Last edited on
I suggest using http://www.cplusplus.com/reference/algorithm/random_shuffle/
1
2
3
4
std::random_shuffle(numbers, numbers+10);
for(int index = 0; i < 10; i++){
    //do whatever you do int your while loop
}

mainframe639 wrote:
I want the program to choose a string once and never repeat the chosen string again.

One way to achieve this is to use a vector of strings to store the data and every time a string is printed remove it from the container.
Topic archived. No new replies allowed.