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) that 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 within the inside-out object model.

USAGE

Module Declaration

Add the following to the top of our application code:

use strict;
use warnings;
use Math::Random::MT::Auto::Range;

This module is strictly OO, and does not export any functions or symbols.

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 is INTEGER, then the range will be LOW to HIGH inclusive (i.e., [LOW, HIGH]). If DOUBLE, then LOW inclusive to HIGH exclusive (i.e., [LOW, HIGH)).

LOW and HIGH must be specified when calling new as a class method.

LO and HI can be used as synonyms for LOW and HIGH, respectively.

'TYPE' => 'INTEGER'
'TYPE' => 'DOUBLE'

Sets the type for the values returned from the PRNG. If TYPE is not specified, it will default to INTEGER if both LOW and HIGH are integers.

The options above are also supported using lowercase and mixed-case (e.g., 'low', 'hi', 'Type', etc.).

Additionally, objects created with this package can take any of the options supported by the Math::Random::MT::Auto class, namely, STATE, SEED and STATE.

$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->set_range_type

Sets the numeric type for the random numbers returned by the PRNG.

$prng->set_range_type('INTEGER');
  # or
$prng->set_range_type('DOUBLE');
$obj->get_range_type

Returns the numeric type ('INTEGER' or 'DOUBLE') for the random numbers returned by the PRNG.

my $type = $prng->get_range_type();
$obj->set_range

Sets the limits for the PRNG's return value range.

$prng->set_range($lo, $hi);
$obj->get_range

Returns a list of the PRNG's range limits.

my ($lo, $hi) = $prng->get_range();
$obj->rrand

Returns a random number of the configured type within the configured range.

my $rand = $prng->rrand();

If the TYPE for the PRNG is INTEGER, then the range will be LOW to HIGH inclusive (i.e., [LOW, HIGH]). If DOUBLE, then LOW inclusive to HIGH exclusive (i.e., [LOW, HIGH)).

In addition to the methods describe above, the objects created by this package also support all the object methods provided by the Math::Random::MT::Auto class.

SEE ALSO

Math::Random::MT::Auto

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.