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
27 provide an example of how to create subclasses of
28 Math::Random::MT::Auto within Object::InsideOut's inside-out object
29 model.
30
32 Add the following to the top of our application code:
33
34 use strict;
35 use warnings;
36 use Math::Random::MT::Auto::Range;
37
38 This module is strictly OO, and does not export any functions or
39 symbols.
40
42 Math::Random::MT::Auto::Range->new
43 Creates a new range-valued PRNG.
44
45 my $prng = Math::Random::MT::Auto::Range->new( %options );
46
47 Available options are:
48
49 'LOW' => $num
50 'HIGH' => $num
51 Sets the limits over which the values return by the PRNG will
52 range. These arguments are mandatory, and "LOW" must not be
53 equal to "HIGH".
54
55 If the "TYPE" for the PRNG is "INTEGER", then the range will be
56 "LOW" to "HIGH" inclusive (i.e., [LOW, HIGH]). If "DOUBLE",
57 then "LOW" inclusive to "HIGH" exclusive (i.e., [LOW, HIGH)).
58
59 "LO" and "HI" can be used as synonyms for "LOW" and "HIGH",
60 respectively.
61
62 'TYPE' => 'INTEGER'
63 'TYPE' => 'DOUBLE'
64 Sets the type for the values returned from the PRNG. If "TYPE"
65 is not specified, it will default to "INTEGER" if both "LOW"
66 and "HIGH" are integers.
67
68 The options above are also supported using lowercase and mixed-case
69 (e.g., 'low', 'hi', 'Type', etc.).
70
71 Additionally, objects created with this package can take any of the
72 options supported by the Math::Random::MT::Auto class, namely,
73 "STATE", "SEED" and "STATE".
74
75 $obj->new
76 Creates a new PRNG in the same manner as
77 "Math::Random::MT::Auto::Range->new".
78
79 my $prng2 = $prng1->new( %options );
80
81 In addition to the methods describe below, the objects created by this
82 package inherit all the object methods provided by the
83 Math::Random::MT::Auto class, including the "-"clone()> method.
84
85 $obj->rrand
86 Returns a random number of the configured type within the
87 configured range.
88
89 my $rand = $prng->rrand();
90
91 If the "TYPE" for the PRNG is "INTEGER", then the range will be
92 "LOW" to "HIGH" inclusive (i.e., [LOW, HIGH]). If "DOUBLE", then
93 "LOW" inclusive to "HIGH" exclusive (i.e., [LOW, HIGH)).
94
95 $obj->set_range_type
96 Sets the numeric type for the random numbers returned by the PRNG.
97
98 $prng->set_range_type('INTEGER');
99 # or
100 $prng->set_range_type('DOUBLE');
101
102 $obj->get_range_type
103 Returns the numeric type ('INTEGER' or 'DOUBLE') for the random
104 numbers returned by the PRNG.
105
106 my $type = $prng->get_range_type();
107
108 $obj->set_range
109 Sets the limits for the PRNG's return value range.
110
111 $prng->set_range($lo, $hi);
112
113 $lo must not be equal to $hi.
114
115 $obj->get_range
116 Returns a list of the PRNG's range limits.
117
118 my ($lo, $hi) = $prng->get_range();
119
121 Capabilities provided by Object::InsideOut are supported by this
122 modules. See "INSIDE-OUT OBJECTS" in Math::Random::MT::Auto for more
123 information.
124
125 Coercion
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
133 • Missing parameter: HIGH
134
135 The LOW and HIGH values for the range must be specified to ->new().
136
137 • Arg to ->set_range_type() must be 'INTEGER' or 'DOUBLE'
138
139 Self explanatory.
140
141 • ->range() requires two numeric args
142
143 Self explanatory.
144
145 • Invalid arguments: LOW and HIGH are equal
146
147 You cannot specify a range of zero width.
148
149 This module will reverse the range limits if they are specified in the
150 wrong order (i.e., it makes sure that "LOW < HIGH").
151
153 Math::Random::MT::Auto
154
155 Object::InsideOut
156
158 Jerry D. Hedden, <jdhedden AT cpan DOT org>
159
161 Copyright 2005 - 2009 Jerry D. Hedden. All rights reserved.
162
163 This program is free software; you can redistribute it and/or modify it
164 under the same terms as Perl itself.
165
166
167
168perl v5.32.1 2021-01-27 Math::Random::MT::Auto::Range(3)