Re: Needing a random number generator for scripting

2001-09-28 Thread Rob Hudson
Check out 'man perlfaq4', and the question titled, "How do I shuffle an array randomly?". It gives a nice algorithm for shuffling, which could be applied similar to below to output shuffled lines. -Rob > On 20010928.0900, Anthony J. Breeds-Taurima said ... > > On Thu, 27 Sep 2001, Joey Hess wrot

Re: Needing a random number generator for scripting

2001-09-27 Thread Jeremy
I want to thank you all for your help. Many of the solutions sounded great. (Makes me wish I knew a bit about some of the other programming languages available, but I'm strictly a beginner, so I'm sticking with bash at the moment). But it's good to know that there's such a knowledgable group out

Re: Needing a random number generator for scripting

2001-09-27 Thread Anthony J. Breeds-Taurima
On Thu, 27 Sep 2001, Joey Hess wrote: > Anthony J. Breeds-Taurima wrote: > > <== randomize ==> > > #!/usr/bin/perl > > ## print a file in random order > > while(<>) { > > $_{$_}=0 > > } > > foreach (keys%_) { > > print > > } > > keys is hardly random. It always outputs the keys in the same

Re: Needing a random number generator for scripting

2001-09-27 Thread Joey Hess
Anthony J. Breeds-Taurima wrote: > <== randomize ==> > #!/usr/bin/perl > ## print a file in random order > while(<>) { > $_{$_}=0 > } > foreach (keys%_) { > print > } keys is hardly random. It always outputs the keys in the same order for a given set of keys. -- see shy jo

Re: Needing a random number generator for scripting

2001-09-27 Thread Rich Puhek
Dave gets my vote for the best answer. I'm a bit biased in that I like a "meat grinder" approach with sed, awk, cat, and a lot of pipesigns, but you've got to admit, his little oneliner script is much tidier than the "here's how it's done in my favorite language" answers. Dave Thayer wrote: >

Re: Needing a random number generator for scripting

2001-09-27 Thread dman
On Thu, Sep 27, 2001 at 10:55:50AM -0400, Noah Meyerhans wrote: | On Thu, Sep 27, 2001 at 09:20:04AM -0400, dman wrote: | > | /dev/random gives random bits. I don't know where it is documented. | > | There is a system call random() (see man 3 random). You could write a | > | wrapper C program to

Re: Needing a random number generator for scripting

2001-09-27 Thread Raja R Harinath
Hi, Jeremy Whetzel <[EMAIL PROTECTED]> writes: > I'm in the process of writing up a script that I need to be able to > "randomly" switch around the lines in a text file. (ala a random mp3 > playlist) Would anyone have any suggestions? I was originally thinking > of using a random number generat

Re: Needing a random number generator for scripting

2001-09-27 Thread Vineet Kumar
* Anthony J. Breeds-Taurima ([EMAIL PROTECTED]) [010926 23:14]: > <== randline ==> > #!/usr/bin/perl > ## print 1 randomline from a file > @_=<>; > print $_[rand$#_]; while this one works, the one Martin posted is a better solution. They're both O(n) in terms of time, but Martin's is O(1) wrt spac

Re: Needing a random number generator for scripting

2001-09-27 Thread Noah Meyerhans
On Thu, Sep 27, 2001 at 09:20:04AM -0400, dman wrote: > | /dev/random gives random bits. I don't know where it is documented. > | There is a system call random() (see man 3 random). You could write a > | wrapper C program to use it in scripts. > > Naw, just use python :-). > > > #!/usr/bin/env

Re: Needing a random number generator for scripting

2001-09-27 Thread dman
On Thu, Sep 27, 2001 at 09:00:26AM +0200, A.R. (Tom) Peters wrote: | On 27 Sep 2001, Jeremy Whetzel wrote: | | > I'm in the process of writing up a script that I need to be able to | > "randomly" switch around the lines in a text file. (ala a random mp3 | > playlist) Would anyone have any suggest

Re: Needing a random number generator for scripting

2001-09-27 Thread A.R. \(Tom\) Peters
On 27 Sep 2001, Jeremy Whetzel wrote: > I'm in the process of writing up a script that I need to be able to > "randomly" switch around the lines in a text file. (ala a random mp3 > playlist) Would anyone have any suggestions? I was originally thinking > of using a random number generator for it,

Re: Needing a random number generator for scripting

2001-09-27 Thread Anthony J. Breeds-Taurima
On Thu, 27 Sep 2001, Dave Thayer wrote: > On Thu, Sep 27, 2001 at 08:45:57PM -0500, Jeremy Whetzel wrote: > > > > I'm in the process of writing up a script that I need to be able to > > "randomly" switch around the lines in a text file. (ala a random mp3 > > playlist) Would anyone have any sugges

Re: Needing a random number generator for scripting

2001-09-27 Thread Dave Thayer
On Thu, Sep 27, 2001 at 08:45:57PM -0500, Jeremy Whetzel wrote: > > I'm in the process of writing up a script that I need to be able to > "randomly" switch around the lines in a text file. (ala a random mp3 > playlist) Would anyone have any suggestions? I was originally thinking > of using a ran

Re: Needing a random number generator for scripting

2001-09-26 Thread Martin F Krafft
cat list | \ perl -e 'srand; rand($.) < 1 && ($line = $_) while <>; print $line;' -- as suggested on this list earlier, it will return a random line out of the file list. if you want the entire list to be shuffled, then search the archives for "random lines" and a post by me. in it's replies, th

Needing a random number generator for scripting

2001-09-26 Thread Jeremy Whetzel
I'm in the process of writing up a script that I need to be able to "randomly" switch around the lines in a text file. (ala a random mp3 playlist) Would anyone have any suggestions? I was originally thinking of using a random number generator for it, but if there's a tool that would work better.