Re: select N random lines in a file
On Sunday 22 August 2004 20:40, Lance Hoffmeyer wrote:
> Hello all,
>
> I would like to write a script that will select N number of
> random lines in a file. Any suggestions on how to do this?
I can't guarantee that this is the best approach, but I would write a
small Perl program. If you don't mind duplicates in the output, read
them into an array of strings then pick N items at random from the
array. If you want to avoid duplicates, read them into a hash so you
can delete each item as it is picked.
Reply to: