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.
You could use
std::random_shufflePossible output:
412536212If you’re using C++11, you can do the same with C-Style arrays like so:
Or if you’re lacking a C++11 compiler you can do the alternative: