#!/usr/local/bin/perl -w eval 'exec /usr/local/bin/perl -w -S $0 ${1+"$@"}' if 0; # not running under some shell # # $Id: random,v 1.1.1.1 2001/06/06 08:55:04 sdague Exp $ # # $Log: random,v $ # Revision 1.1.1.1 2001/06/06 08:55:04 sdague # initial import # # Revision 1.1 2001/05/14 00:49:39 sdague # added more files # # Revision 1.1 1999/02/28 22:10:55 abigail # Initial revision # # use strict; use Getopt::Std; my ($VERSION) = '$Revision: 1.1.1.1 $' =~ /([.\d]+)/; my $warnings = 0; END { close STDOUT || die "$0: can't close stdout: $!\n"; $? = 1 if $? == 255; # from die } # Print a usuage message on a unknown option. # Requires my patch to Getopt::Std of 25 Feb 1999. $SIG {__WARN__} = sub { if (substr ($_ [0], 0, 14) eq "Unknown option") {die "Usage"}; require File::Basename; $0 = File::Basename::basename ($0); $warnings = 1; warn "$0: @_"; }; $SIG {__DIE__} = sub { require File::Basename; $0 = File::Basename::basename ($0); if (substr ($_ [0], 0, 5) eq "Usage") { die < 1; my $denominator = @ARGV ? shift : 2; die "Usage" if $denominator =~ /\D/ || $denominator == 0; exit int rand $denominator if exists $options {e}; $| = 1 if exists $options {r}; my $frac = 1 / $denominator; while (<>) {print if $frac >= rand;} exit $warnings; __END__ =pod =head1 NAME random -- display lines at random, or exit with a random value. =head1 SYNOPSIS random [-er] [denominator] =head1 DESCRIPTION I reads line from standard input, and displays each line on standard output which chance 1 / I. If the I<-e> option is given, I exits with a value randomly choosen from C<0> to C inclusive. If no I is given, 2 is used. =head2 OPTIONS I accepts the following options: =over 4 =item -e Exit with a value randomly choosen from C<0> to C inclusive. Do not read input, or display output. =item -r Use unbuffered output. =back =head1 ENVIRONMENT The working of I is not influenced by any environment variables. =head1 BUGS There are no known bugs in I. =head1 REVISION HISTORY $Log: random,v $ Revision 1.1.1.1 2001/06/06 08:55:04 sdague initial import Revision 1.1 2001/05/14 00:49:39 sdague added more files Revision 1.1 1999/02/28 22:10:55 abigail Initial revision =head1 AUTHOR The Perl implementation of I was written by Abigail, I. =head1 COPYRIGHT and LICENSE This program is copyright by Abigail 1999. This program is free and open software. You may use, copy, modify, distribute and sell this program (and any modified variants) in any way you wish, provided you do not restrict others to do the same. =cut