Selecting a random string from my string array

Hi, probably very easy but never done it before! if I have a string array like the following

string name [4] = {"harry", "dave", "colin", "sally"};

I can cout as usual using

cout << name[3] ;

cout's sally, but how can I do a random name instead of [3] in the brackets is there a symbol I can use for random which will select 0 to 3 for me?
Last edited on
try searching for rand() function
tried a few different versions but cant get it working , could you provide an example please?

int RandIndex = rand() % 3; //generates a random number between 0 and 3

not actually generating a number between 0-3 just the same number (the max it will allow) rand() % 3 will allow 2, 4 does 3 etc so how can I get it to randomize not just do the max..

Fixed, I didnt include srand (time(NULL));, initialized and working now :)
Last edited on
Topic archived. No new replies allowed.