Hacker News new | ask | show | jobs
by wodenokoto 3899 days ago
How does this handle files that are gigs in size? It looks to me like you load the entire file into memory and pass it along, shuffled.
2 comments

If you have an unknown input size and a finite number of requested output lines, you can still do it in O(n) and no additional memory, by having a steadily-decreasing chance of replacing one of the outputs with the next line.