in reply to Re: Opening random files then reading random lines from file.
in thread Opening random files then reading random lines from file.

Since you need to know the number of the lines in the file,
No, you don't. There's a fair and linear way to pick a random element from a stream of unknown length, and its algorithm (which can be implemented as a one-liner) has been displayed in a post before yours.

Detailed analysis can be found in The Art of Computer Programming, by Donald Knuth. Volume 1, IIRC.

  • Comment on Re^2: Opening random files then reading random lines from file.