random k-sample of a file
    Andrei Alexandrescu 
    SeeWebsiteForEmail at erdani.org
       
    Thu Oct  9 11:56:48 PDT 2008
    
    
  
I just ran across a nice little problem that I wanted to share as an 
exercise for the interested in futile pastimes.
The challenge, should you accept it, is to write a program that given a 
number k and a file, outputs k lines picked uniformly at random from the 
file. (If the file has less than k lines, it should all be output.) The 
file's size is unbounded so loading it in memory is not an option. How'd 
you go about it?
Andrei
    
    
More information about the Digitalmars-d
mailing list