0

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

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by firstPerson
0

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

0

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

0

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)
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.