1Math::Random::MT::Auto:U:sRearngCeo(n3t)ributed Perl DocMuamtehn:t:aRtainodnom::MT::Auto::Range(3)
2
3
4
6 Math::Random::MT::Auto::Range - Range-valued PRNGs
7
9 use strict;
10 use warnings;
11 use Math::Random::MT::Auto::Range;
12
13 # Integer random number range
14 my $die = Math::Random::MT::Auto::Range->new(LO => 1, HI => 6);
15 my $roll = $die->rrand();
16
17 # Floating-point random number range
18 my $compass = Math::Random::MT::Auto::Range->new(LO => 0, HI => 360,
19 TYPE => 'DOUBLE');
20 my $course = $compass->rrand();
21
23 This module creates range-valued pseudorandom number generators (PRNGs)
24 that return random values between two specified limits.
25
26 While useful in itself, the primary purpose of this module is to pro‐
27 vide an example of how to create subclasses of Math::Random::MT::Auto
28 within Object::InsideOut's inside-out object model.
29
31 Add the following to the top of our application code:
32
33 use strict;
34 use warnings;
35 use Math::Random::MT::Auto::Range;
36
37 This module is strictly OO, and does not export any functions or sym‐
38 bols.
39
41 Math::Random::MT::Auto::Range->new
42 Creates a new range-valued PRNG.
43
44 my $prng = Math::Random::MT::Auto::Range->new( %options );
45
46 Available options are:
47
48 'LOW' => $num
49 'HIGH' => $num
50 Sets the limits over which the values return by the PRNG will
51 range. These arguments are mandatory, and "LOW" must not be
52 equal to "HIGH".
53
54 If the "TYPE" for the PRNG is "INTEGER", then the range will be
55 "LOW" to "HIGH" inclusive (i.e., [LOW, HIGH]). If "DOUBLE",
56 then "LOW" inclusive to "HIGH" exclusive (i.e., [LOW, HIGH)).
57
58 "LO" and "HI" can be used as synonyms for "LOW" and "HIGH",
59 respectively.
60
61 'TYPE' => 'INTEGER'
62 'TYPE' => 'DOUBLE'
63 Sets the type for the values returned from the PRNG. If "TYPE"
64 is not specified, it will default to "INTEGER" if both "LOW"
65 and "HIGH" are integers.
66
67 The options above are also supported using lowercase and mixed-case
68 (e.g., 'low', 'hi', 'Type', etc.).
69
70 Additionally, objects created with this package can take any of the
71 options supported by the Math::Random::MT::Auto class, namely,
72 "STATE", "SEED" and "STATE".
73
74 $obj->new
75 Creates a new PRNG in the same manner as "Math::Ran‐
76 dom::MT::Auto::Range->new".
77
78 my $prng2 = $prng1->new( %options );
79
80 In addition to the methods describe below, the objects created by this
81 package inherit all the object methods provided by the Math::Ran‐
82 dom::MT::Auto class, including the "-"clone()> method.
83
84 $obj->rrand
85 Returns a random number of the configured type within the config‐
86 ured range.
87
88 my $rand = $prng->rrand();
89
90 If the "TYPE" for the PRNG is "INTEGER", then the range will be
91 "LOW" to "HIGH" inclusive (i.e., [LOW, HIGH]). If "DOUBLE", then
92 "LOW" inclusive to "HIGH" exclusive (i.e., [LOW, HIGH)).
93
94 $obj->set_range_type
95 Sets the numeric type for the random numbers returned by the PRNG.
96
97 $prng->set_range_type('INTEGER');
98 # or
99 $prng->set_range_type('DOUBLE');
100
101 $obj->get_range_type
102 Returns the numeric type ('INTEGER' or 'DOUBLE') for the random
103 numbers returned by the PRNG.
104
105 my $type = $prng->get_range_type();
106
107 $obj->set_range
108 Sets the limits for the PRNG's return value range.
109
110 $prng->set_range($lo, $hi);
111
112 $lo must not be equal to $hi.
113
114 $obj->get_range
115 Returns a list of the PRNG's range limits.
116
117 my ($lo, $hi) = $prng->get_range();
118
120 Capabilities provided by Object::InsideOut are supported by this mod‐
121 ules. See "INSIDE-OUT OBJECTS" in Math::Random::MT::Auto for more
122 information.
123
124 Coercion
125
126 Object coercion is supported in the same manner as documented in See
127 "Coercion" in Math::Random::MT::Auto except that the underlying random
128 number method is "->rrand()".
129
131 * Missing parameter: LOW
132 * Missing parameter: HIGH
133 The LOW and HIGH values for the range must be specified to ->new().
134
135 * Arg to ->set_range_type() must be 'INTEGER' or 'DOUBLE'
136 Self explanatory.
137
138 * ->range() requires two numeric args
139 Self explanatory.
140
141 * Invalid arguments: LOW and HIGH are equal
142 You cannot specify a range of zero width.
143
144 This module will reverse the range limits if they are specified in the
145 wrong order (i.e., it makes sure that "LOW < HIGH").
146
148 Math::Random::MT::Auto
149
150 Object::InsideOut
151
153 Jerry D. Hedden, <jdhedden AT cpan DOT org>
154
156 Copyright 2005, 2006 Jerry D. Hedden. All rights reserved.
157
158 This program is free software; you can redistribute it and/or modify it
159 under the same terms as Perl itself.
160
161
162
163perl v5.8.8 2006-10-09 Math::Random::MT::Auto::Range(3)