#!/usr/bin/perl -w # # rand-exp-dist-vals - # generate a series of values of X, an exponentially # distributed continuous random variable # # $Id: rand-exp-dist-vals,v 1.2 2001/08/29 14:36:45 thor Exp $ # # Tom Moertel # 29 Aug 2001 use strict; use File::Basename; # parse command line my $opt_cumulative; if (@ARGV && $ARGV[0] =~ /--?c/) { $opt_cumulative = shift; } if (@ARGV != 2) { my $cmd = basename($0); print STDERR "Usage: $cmd [--cumulative] lambda count\n"; exit 1; } # generate the output series my ($lambda, $count) = @ARGV; my $time = 0.0; for (1 .. $count) { $time = 0.0 unless $opt_cumulative; $time -= log(1.0 - rand) / $lambda; print $time, "\n"; } =head1 NAME rand-exp-dist-vals - generate a series of values of X, an exponentially distributed continuous random variable =head1 SYNOPSIS B [B<--cumulative>] I I =head1 DESCRIPTION Generate a series of I values of I, an exponentially distributed continuous random variable with parameter I. The parameter I is the average number of occurrences (per unit time) of the event described by I. (One should note that the parameter I is also the reciprocal of the mean inter-occurrence time.) The output series is expressed in multiples of the unit time. For example, if the unit time is one hour, the output series is expressed in hours. Likewise, if the unit time is one day, the output series is expressed in days. =head1 OPTIONS =over 4 =item B<--cumulative> (also B<-c>) Generate cumulative values, i.e., every value is added to a running total, and the running total is output at each step. =back =head1 ABOUT THE EXPONENTIAL DISTRIBUTION The exponential probability distribution is useful for modeling events that have the following characteristics: =over 4 =item * Each event is independent of any others. =item * The likelihood that an event will occur during a unit interval of time is independent of the amount of time that has already passed (i.e., the distribution is memoryless). =item * The number of events that occur during a unit interval of time is independent of the number that occurred in any previous interval. (This follows from the previous two points.) =back The distribution is useful for modeling real-world phenomena such as the time-to-next-failure of computer components or the time between arrivals of HTTP requests on the world wide web. Use the B<--cumulative> option to generate cumulative values, which are more useful for modeling I events occur rather than the I