[Wellington-pm] Select at random from a list

Philip Plane philip at xinqu.net
Fri Jul 14 16:44:07 PDT 2006

Hi Guys,

I have a little script I wrote to return a randomly selected mp3 from a
playlist. It works, but doesn't seem to be as random as I hoped. Any
comment on a better way of doing this?

-- start script --
#! /bin/perl -w
use CGI;

$q = new CGI;
open PLAYLIST, "/mp3/playlist.txt" or die "Couldn't open playlist: $!\n";
@playlist = <PLAYLIST>;

$mp3 = $playlist[int(rand(scalar(@playlist)))];
open MP3, $mp3 or die "Couldn't open $mp3: $!\n";
print $q->header(-type=>'audio/mpeg', -Content_length=>(stat MP3)[7]);
print <MP3>;
close MP3;
-- end script --

Philip Plane    _____   philip at xinqu.net
  ---------------( )---------------
Glider pilots have no visible means of support

More information about the Wellington-pm mailing list