NCCI Perl Documentation Random(3)
NAME
Random - Class to spit out pseudo-random numbers.
SYNOPSIS
# Access to modules (see the NOTES section for setup)
BEGIN {
...
push (@INC, "../sys/csbase/lib");
}
use Random;
$rand = new Random ();
# Real number N in the range 0 <= N < 1
$randNumber = $rand->next ();
# Real number N in the range 0 <= N < $upper
$randNumber = $rand->next ($upper);
# Integer in the range 10 .. 20 (inclusive)
$randInteger = $rand->nextInteger (10, 20);
# Return a 1 17% of the time, a 0 83% of the time
$toss = $rand->probability (17);
DESCRIPTION
This class provides a slightly more convenient interface for
fetching pseudo-random numbers than the Perl interface.
Note that all objects of this class use the SAME underlying
rand/srand Perl calls, so they SHARE THE SAME RANDOM
SEQUENCE.
Functions
Random->new ([$accessMode])
Create an object to spit out pseudo-random numbers and
seed the random number generator.
The $alternateSeed argument is a replacement for the
default random number seed, which is the expression
"time () ^ ($$ + ($$ << 15))".
next ($upperLimit)
Return a new random number N in the range 0 <= N < abs
($upperLimit). The $upperLimit defaults to 1.
nextInteger ($lowerLimit, $upperLimit)
Return a new random integer N in the range abs
($lowerLimit) <= N <= abs ($upperLimit)
19/Mar/01 Last change: perl 5.004, patch 01 1
NCCI Perl Documentation Random(3)
The $lowerLimit defaults to 0 and the $upperLimit
defaults to 1. If abs ($upperLimit) < abs
($lowerLimit), nextInteger () returns -1.
probability ($percentage)
Given a probability $percentage in the range 0 .. 100,
return 1 $percentage of the time.
previous ()
Return the most recent random number returned by the
next() method.
If the next method has never been called, previous()
returns a number as if next () had been called (that is,
it returns N: 0 <= N < 1);
Calls to nextInteger() and percentage() do not reset the
value returned by previous().
NOTES
This module has not yet been set up for "installation" in
your local Perl. We currently use a set of conventions for
access to this module, until the install procedures are
developed:
- The source code lives on development and production hosts
in the directory /Volumes/app/cs/csbase/lib.
- By convention, a project maintains perl scripts in
subdirectories of some top-level directory, which we will
call $TOP.
- By convention, projects establish a $TOP/sys directory
which contains a symbolic link from csbase to
/Volummes/app/cs/csbase.
- To get access to the modules, you typically include a
BEGIN of the form:
BEGIN {
...
push (@INC, "../sys/csbase/lib");
}
AUTHOR
Clint Goss <clint@goss.com>, October 1997