How do I read a random line from one file?

前端 未结 11 762
灰色年华
灰色年华 2020-12-04 20:03

Is there a built-in method to do it? If not how can I do this without costing too much overhead?

11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 20:29

    Seek to a random position, read a line and discard it, then read another line. The distribution of lines won't be normal, but that doesn't always matter.

提交回复
热议问题