NAME
Math::Random::MT::Auto::Range - Range-valued PRNGs
SYNOPSIS
use strict;
use warnings;
use Math::Random::MT::Auto::Range;
# Integer random number range
my $die = Math::Random::MT::Auto::Range(LO => 1, HI => 6);
my $roll = $die->rrand();
# Floating-point random number range
my $compass = Math::Random::MT::Auto::Range(LO => 0, HI => 360,
TYPE => 'DOUBLE');
my $course = $compass->rrand();
DESCRIPTION
This module creates range-valued pseudo-random number generators (PRNGs) which return random values between two specified limits.
While useful in itself, the primary purpose of this module is to provide an example of how to create subclasses of Math::Random::MT::Auto.
USAGE
- Module Declaration
-
This module does not export any functions or symbols.
use strict; use warnings; use Math::Random::MT::Auto::Range;
- Math::Random::MT::Auto::Range->new
-
Creates a new range-valued PRNG.
my $prng = Math::Random::MT::Auto::Range->new( %options );
Available options are:
- 'LOW' => $num
- 'HIGH' => $num
-
Sets the limits over which the values return by the PRNG will range. If the
TYPE
for the PRNG isINTEGER
, then the range will beLOW
toHIGH
inclusive (i.e., [LOW, HIGH]). IfDOUBLE
, thenLOW
inclusive toHIGH
exclusive (i.e., [LOW, HIGH)).LOW
andHIGH
must be specified when callingnew
as a class method. - 'TYPE' => 'INTEGER'
- 'TYPE' => 'DOUBLE'
-
Sets the type for the values returned from the PRNG. If
TYPE
is not specified, it will default toINTEGER
if bothLOW
andHIGH
are integers.
- $obj->new
-
Creates a new PRNG, using any specified options, and then using attributes from the referenced PRNG.
my $prng2 = $prng1->new( %options );
With no options, the new PRNG will be a complete clone of the referenced PRNG.
- $obj->range
-
Returns a list of the PRNG's range limits.
my ($lo, $hi) = $prng->range();
If called with arguments, it sets the limits for the PRNG's return value range.
$prng->range($lo, $hi);
- $obj->range_type
-
Returns the type for the return values from the PRNG.
my $type = $prng->range_type();
If called with an argument, it sets the PRNG's type.
$prng->range_type('INTEGER'); $prng->range_type('DOUBLE');
- $obj->rrand
-
Returns a random number of the configured type within the configured range.
my $rand = $prng->rrand();
If the
TYPE
for the PRNG isINTEGER
, then the range will beLOW
toHIGH
inclusive (i.e., [LOW, HIGH]). IfDOUBLE
, thenLOW
inclusive toHIGH
exclusive (i.e., [LOW, HIGH)).
SEE ALSO
AUTHOR
Jerry D. Hedden, <jdhedden AT 1979 DOT usna DOT com>
COPYRIGHT AND LICENSE
Copyright 2005 Jerry D. Hedden. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.