   [Java] What is the best way to get a random line from a file?
  What I am trying to do is randomly pick a line of a text file. The file is set up so that there is one word per line and overall length of the file is unknown. So, the file could look like this:SteveJoeAdamJasonJoe, againOr like this:appleorangestrawberrykiwilimegrapepineapplecherrymangopeachYou get the idea.I need something that, no matter how many lines there are, it will randomly pick one.   
  I assume by "randomly" you mean "uniformly randomly". In that case, you have to count the lines, pick a random number in that range and print the corresponding line. You'll either have to keep all the lines in memory or read the file again.EDIT: Actually, I just thought of a better method: For each line you read, generate a random number. Keep at all times the minimum random number you've seen and the line on which it happened. When you are done reading the file, print that line.   