summaryrefslogtreecommitdiff
path: root/lib/rand.pm
blob: bf42e7d9a534b7304b6e7e350d5ded4533a24494 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 <FORTUNES>;
	close FORTUNES;

	chomp $line;
	return $line;
	}

1;