From e9192b3d42660a5781101df4357d276318151e8a Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 2 Aug 2013 17:14:41 -0500 Subject: cgi-bin & lib --- lib/rand.pm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lib/rand.pm (limited to 'lib/rand.pm') diff --git a/lib/rand.pm b/lib/rand.pm new file mode 100644 index 0000000..bf42e7d --- /dev/null +++ b/lib/rand.pm @@ -0,0 +1,20 @@ +#!/usr/bin/perl + +sub get_random_line + { + my ($file) = @_; + my $line; + + # inscrutable random line algorithm -- from the camel book + # $. is the number of the last line accessed + open FORTUNES, "$BUCKY_FORTUNES/$file" or error("Could not access fortune $file"); + srand; + rand($.) < 1 && ($line = $_) while ; + close FORTUNES; + + chomp $line; + return $line; + } + +1; + -- cgit v1.2.3-70-g09d2