A quick question about random_shuffle()

Hi just a quick question! I've written my code below and I was wondering if there is a way of using an algorithm like random_shuffle() to achieve the same thing? Do I have to use vectors?
Many thanks.
1
2
3
4
5
6
7
8
9
10
11
12
13
  string word = "Game Over!";
	srand(time(0));
	 									
    int length = word.size();
    for (int i=0; i<length; i++)
    {
        int index1 = (rand() % length);
        int index2 = (rand() % length);
        char temp = word[index1];
        word[index1] = word[index2];
        word[index2] = temp;
    }    
    cout << "The jumbled word is: " << word;
Last edited on
Topic archived. No new replies allowed.