in reply to
Opening random files then reading random lines from file.
I see that most part of your question has already been answered. However, one more note about random line selection: Since you need to know the number of the lines in the file, you have to read it at least once. Unless the file is really big, I would therefore slurp the file into an array, and then select a line at random from this array.
UPDATE: I was wrong. As we can see from this comment, it is indeed NOT necessary to slurp the whole file!
Ronald Fischer <email@example.com>