Re: random lines

2001-07-02 Thread Joost Kooij
On Mon, Jul 02, 2001 at 01:46:29PM -0400, Steven Smolinski wrote: > On Mon, Jul 02, 2001 at 11:24:40PM +0200, Martin F. Krafft wrote: > > also sprach Joost Kooij (on Mon, 02 Jul 2001 11:15:38PM +0200): > > > perl -e 'print map {$_->[1]} sort {$a->[0]<=>$b->[0]} map {[rand,$_]} <>' > > > file > >

Re: [users] Re: random lines

2001-07-02 Thread Martin F. Krafft
also sprach Steven Smolinski (on Mon, 02 Jul 2001 02:47:49PM -0400): > Huh? I thought you wanted one random line chosen out of several? yeah well, so did i. but in retrospect, for a random playlist of albums for a custom script to be used with mpg123, permutations make more sense. but i still do

Re: [users] Re: random lines

2001-07-02 Thread Steven Smolinski
On Tue, Jul 03, 2001 at 12:23:20AM +0200, Martin F. Krafft wrote: > also sprach Steven Smolinski (on Mon, 02 Jul 2001 01:46:29PM -0400): > > That algorithm is one of the purest distillations of beauty I've ever > > seen. :-) Remember, the perlfaq is far more peer-reviewed than almost > > any othe

Re: [users] Re: random lines

2001-07-02 Thread Martin F. Krafft
also sprach Steven Smolinski (on Mon, 02 Jul 2001 01:46:29PM -0400): > That algorithm is one of the purest distillations of beauty I've ever > seen. :-) Remember, the perlfaq is far more peer-reviewed than almost > any other source of info. okay, okay. i believe you. did you give me a link for t

Re: random lines

2001-07-02 Thread Steven Smolinski
On Mon, Jul 02, 2001 at 11:24:40PM +0200, Martin F. Krafft wrote: > also sprach Joost Kooij (on Mon, 02 Jul 2001 11:15:38PM +0200): > > perl -e 'print map {$_->[1]} sort {$a->[0]<=>$b->[0]} map {[rand,$_]} <>' > > file > > that's perfect! > > the other perl algorithm permitted did a scan through

Re: random lines

2001-07-02 Thread Martin F. Krafft
also sprach Joost Kooij (on Mon, 02 Jul 2001 11:15:38PM +0200): > perl -e 'print map {$_->[1]} sort {$a->[0]<=>$b->[0]} map {[rand,$_]} <>' file that's perfect! the other perl algorithm permitted did a scan through the file, halting on a given line according to a random number. i may well be wron

Re: random lines

2001-07-02 Thread Joost Kooij
On Sun, Jul 01, 2001 at 05:15:13PM +0200, Martin F. Krafft wrote: > hey, > do you guys know of a smart way to access random lines in a file? so > if a file had lines 1-5, 5 random reads would return something like > line3, line1, line2, line5, line4? you get the picture... oh, and that > preferably

Re: [users] Re: random lines

2001-07-01 Thread Martin F. Krafft
also sprach Thomas J. Hamman (on Sun, 01 Jul 2001 01:32:54PM -0400): > I like Python. :) mailman is written in python, right? from my experience, python scripts always take 1-2 seconds to load before they execute. that's kind of a pain. i don't know how python and shell interact - since i plan to

Re: [users] Re: random lines

2001-07-01 Thread Thomas J. Hamman
On Sun, Jul 01, 2001 at 06:12:49PM +0200, Martin F. Krafft wrote: > > from random import * > > from linecache import * > > print getline('~/.muttrc',randrange(1,20)) > > except that hardcodes the file length, does it not? Yep, like I said it was a quickie example. Here's something that wouldn't

[users] Re: random lines

2001-07-01 Thread Steven Smolinski
"Martin F. Krafft" <[EMAIL PROTECTED]> wrote: > also sprach Thomas J. Hamman (on Sun, 01 Jul 2001 11:58:32AM -0400): > > What exactly is this for? You could use fortune and strfile. Make > > the text file with a % symbol between each selection, like this: > > a list of albums that i have on mp3

Re: [users] Re: random lines

2001-07-01 Thread Martin F. Krafft
also sprach Thomas J. Hamman (on Sun, 01 Jul 2001 11:58:32AM -0400): > What exactly is this for? You could use fortune and strfile. Make the > text file with a % symbol between each selection, like this: a list of albums that i have on mp3 format.and the desire to have a script that play

Re: random lines

2001-07-01 Thread Thomas J. Hamman
On Sun, Jul 01, 2001 at 05:15:13PM +0200, Martin F. Krafft wrote: > hey, > do you guys know of a smart way to access random lines in a file? so > if a file had lines 1-5, 5 random reads would return something like > line3, line1, line2, line5, line4? you get the picture... oh, and that > preferably

Re: random lines

2001-07-01 Thread Moritz Schulte
"Martin F. Krafft" <[EMAIL PROTECTED]> writes: > do you guys know of a smart way to access random lines in a file? Hmm, here's a really quick & dirty hack: $ cat data.txt foo bar baz quux $ randline() { head -$(($RANDOM % $(wc -l < $1) + 1)) $1 | tail -1; } $ randline data.txt quux $ randline da