Re: select N random lines in a file

From: Adam Funk (a24061_at_yahoo.com)
Date: 08/22/04

  • Next message: Ed Sutherland: "Re: GUI Database?"
    Date: Sun, 22 Aug 2004 19:53:04 GMT
    To: debian-user@lists.debian.org
    
    

    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.

    -- 
    To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org 
    with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
    

  • Next message: Ed Sutherland: "Re: GUI Database?"

    Relevant Pages

    • Re: string retrieval issue
      ... Chicago Bears|NFC North ... not writing the third element back to the array). ... You didn't include it in your script. ... Fear is the mind-killer. ...
      (comp.lang.perl.misc)
    • Re: even rows for checkbox forms with no splitting of boxes from values
      ... 'mod' on the array length with a denominator equal to the width of the row, ... State saving really depends on what the script is already doing. ... So I usually roll my own checkboxes. ... #this is to create an array with 25-50 strings 2-10 in length ...
      (comp.infosystems.www.authoring.cgi)
    • Re: settimeout needs alert() ???
      ... function slider { ... and use script to replace the src and title attributes. ... are downloaded completely. ... The usual strategy is to load all of the images in to an array of image ...
      (comp.lang.javascript)
    • Re: Changing file output format
      ... > I would like to change output format of a file from: ... The chomp function is for situations where you may not know whether a line is terminated by a newline. ... If you are not manipulating the data set as a whole, there is no good reason to put it into an array. ... > However, the script did not print the entire array elements all at once, and that the elements are not joined together in the array, as shown in the output below: ...
      (perl.beginners)
    • Re: library (random numbers)
      ... Get into the habbit of using ... With such small libraries/scripts as these, ... Now you've FUBARed your script. ... $#arr is the last index of the array. ...
      (perl.beginners)