Picking a random riddle

I make loads of riddle but I need to make it pick a random riddle from it.

how would I do do it?

Thank you in advance.
Last edited on
closed account (Lv0f92yv)
What do you mean by random riddle?

What database is this, and how do you plan to access it?

Edit: 60 second response - not trolling, promise.
Last edited on
When I said database basicly I put made loads of riddles in the script.

Sorry i'm finding it hard to get it out my head what I mean :(
closed account (Lv0f92yv)
Do you mean some kind of file with different 'riddles' on each line? And you want to choose a random line from that file (and thus a random riddle)?
Yeah
closed account (Lv0f92yv)
Have a look at file IO: http://www.cplusplus.com/doc/tutorial/files/

and the srand function, for pseudorandom numbers.

Get the number of lines in the file, get a random number that is within that number of lines, and extract the given line based on the number using the filestream pointer.
Note that you should probably use use srand(time()).
http://cplusplus.com/reference/clibrary/cstdlib/
http://cplusplus.com/reference/clibrary/ctime/time/

To get the number of lines, use getline(ifstream, garbagestring) until you find an EOF. Maybe using good() will help?
http://cplusplus.com/reference/iostream/ios/good/

-Albatross
Topic archived. No new replies allowed.