I hope this is a very simple question, but how can you random a string within a array
For example, for vaules ill do this
`
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
srand ( time(NULL) ); //initialize the random seed
const char arrayNum[4] = {'1', '3', '7', '9'};
int RandIndex = rand() % 4;
int RandIndex_2 = rand() % 4;
int RandIndex_3 = rand() % 4;
int RandIndex_4 = rand() % 4; //generates a random number between 0 and 3
cout << arrayNum[RandIndex] << endl;;
system("PAUSE");
return 0;
} `
how can i apply this if there is string within the arraynum
I have come across something like this in my serach for an answer though
std::string textArray[4] = {"Cake", "Toast", "Butter", "Jelly"};
but all I come across is a hex answer which does not change on it's own. so therefore I am going to assume it is probably not even randomized.
std::random_shufflewould be a better choice if you don't want duplicates. As it is, you could very well pick the same one twice.