#!/usr/local/bin/perl -T -I. # Random Story Selector, v. 1.1 # by Sarah T. (harriet_spy@yahoo.com) # This script works with Naomi Novik's Automated Archive package # to return a randomly-selected story from an AA archive. use AutomatedArchiveSettings; unshift (@INC, @LIBDIR); require 'archiveLib.pl'; require 'cgi-lib.pl'; my ($total_stories, $random_key, $file_location, $partial_location); &readDB; # this reads in the hash that indexes stories #next, we pick a random key number and pull the location of the story associated with it &CgiDie ("Not enough files!", "Not enough files to choose one!") unless (%FILES and (scalar keys %FILES > 1)); $total_stories=scalar keys %FILES; $random_key=&random_int (1,$total_stories); $partial_location=$FILES{$random_key}{Location}; $file_location="$ARCHIVEURL/$partial_location" . ".html"; #then, we redirect the user to it print "Location: $file_location\n"; print "\n"; #subroutine lifted from perlfaq, of course sub random_int { my($min, $max) = @_; return $min if $min == $max; ($min, $max) = ($max, $min) if $min > $max; return $min + int rand(1 + $max - $min); } ;