1
package Games::ABC_Path::MicrosoftRand;
9
Games::ABC_Path::MicrosoftRand - a pseudo-random number generator compatible
18
our $VERSION = '0.1.0';
23
use Games::ABC_Path::MicrosoftRand;
25
my $randomizer = Games::ABC_Path::MicrosoftRand->new(seed => 24);
27
my $random_digit = $randomizer->rand_max(10);
31
This is a random number generator use by Games::ABC_Path::Generator, which
32
emulates the one found in Microsoft's Visual C++. It was utilised here, out
33
of familiarity and accessibility, because it is commonly used to generate
34
Freecell layouts in the Freecell world (see
35
L<http://en.wikipedia.org/wiki/FreeCell_%28Windows%29> ).
41
use Class::XSAccessor {
43
accessors => [qw(seed)],
49
$self->seed(($self->seed() * 214013 + 2531011) & (0x7FFF_FFFF));
50
return (($self->seed >> 16) & 0x7fff);
55
my ($self, $max) = @_;
57
return ($self->rand() % $max);
62
my ($self, $deck) = @_;
68
my $j = $self->max_rand($i+1);
69
@$deck[$i,$j] = @$deck[$j,$i];
76
=head1 SUBROUTINES/METHODS
80
The constructor. Accepts a numeric seed as an argument.
82
my $randomizer = Games::ABC_Path::MicrosoftRand->new(seed => 1);
84
=head2 $randomizer->rand()
86
Returns a random integer from 0 up to 0x7fff - 1.
88
my $n = $randomizer->rand()
90
=head2 $randomizer->max_rand($max)
92
Returns a random integer in the range 0 to ($max-1).
94
my $n = $randomizer->max_rand($max);
95
# $n is now between 0 and $max - 1.
97
=head2 $randomizer->seed($seed)
99
Can be used to re-assign the seed of the randomizer (though not recommended).
101
=head2 my $array_ref = $randomizer->shuffle(\@array)
103
Shuffles the array reference of the first argument, B<destroys it> and returns
104
it. This is using the fisher-yates shuffle.
110
Shlomi Fish, L<http://www.shlomifish.org/> .
114
Please report any bugs or feature requests to C<bug-games-abc_path-generator at rt.cpan.org>, or through
115
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Games-ABC_Path-Generator>. I will be notified, and then you'll
116
automatically be notified of progress on your bug as I make changes.
123
You can find documentation for this module with the perldoc command.
125
perldoc Games::ABC_Path::MicrosoftRand
128
You can also look for information at:
132
=item * RT: CPAN's request tracker (report bugs here)
134
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Games-ABC_Path-Generator>
136
=item * AnnoCPAN: Annotated CPAN documentation
138
L<http://annocpan.org/dist/Games-ABC_Path-Generator>
142
L<http://cpanratings.perl.org/d/Games-ABC_Path-Generator>
146
L<http://search.cpan.org/dist/Games-ABC_Path-Generator/>
151
=head1 ACKNOWLEDGEMENTS
154
=head1 LICENSE AND COPYRIGHT
156
Copyright 2011 Shlomi Fish.
158
This program is distributed under the MIT (X11) License:
159
L<http://www.opensource.org/licenses/mit-license.php>
161
Permission is hereby granted, free of charge, to any person
162
obtaining a copy of this software and associated documentation
163
files (the "Software"), to deal in the Software without
164
restriction, including without limitation the rights to use,
165
copy, modify, merge, publish, distribute, sublicense, and/or sell
166
copies of the Software, and to permit persons to whom the
167
Software is furnished to do so, subject to the following
170
The above copyright notice and this permission notice shall be
171
included in all copies or substantial portions of the Software.
173
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
174
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
175
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
176
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
177
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
178
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
179
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
180
OTHER DEALINGS IN THE SOFTWARE.
185
1; # End of Games::ABC_Path::MicrosoftRand