Choosing a random string?
Hi there,
I need some help on how I would randomly choose a string from an array? So far, I have created a text file of 100 strings that is read from a file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main() {
// Initialize random numbers
srand(time(0));
// ...
string str = array[rand() % size];
cout << str << endl;
}
|
Topic archived. No new replies allowed.