Hey gang,

I have a string array containing 10 words,I would like to randomly pick one of these words, how do I go about it,cant find any tutorials????

Thanks Buzz

use rand() function to generate the the index of the Srting array and get that string..

So basically i must use the rand function to pick a number between 0 and 9 and remove the element with that index and store it in another variable

Hi again, I can generate the random number but how do i compare this with the array index????

Do something like this :

#include <iostream>
#include <ctime> //needed for time

int main(){
 srand( time(0) ); //seed random number generator
 string name[3] = { "luke" , "tony", "robert" };
 string randomName = rand() % 3; //return a number from [0,3)
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.