File Coverage

blib/lib/Math/RNG/Microsoft.pm
Criterion Covered Total %
statement 29 29 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod 2 2 100.0
total 41 41 100.0


line stmt bran cond sub pod time code
1             package Math::RNG::Microsoft;
2             $Math::RNG::Microsoft::VERSION = '0.4.0';
3 2     2   368576 use 5.006;
  2         6  
4 2     2   11 use strict;
  2         3  
  2         54  
5 2     2   9 use warnings;
  2         3  
  2         174  
6              
7              
8 2     2   608 use integer;
  2         16  
  2         14  
9              
10 2     2   634 use parent 'Math::RNG::Microsoft::Base';
  2         395  
  2         14  
11              
12             use Class::XSAccessor {
13 2         18 constructor => 'new',
14             accessors => [qw(seed)],
15 2     2   1202 };
  2         5583  
16              
17             sub rand
18             {
19 24     24 1 438089 my $self = shift;
20 24         62 $self->seed( ( $self->seed() * 214013 + 2531011 ) & (0x7FFF_FFFF) );
21 24         59 return scalar( ( $self->seed >> 16 ) & 0x7fff );
22             }
23              
24             sub _custom_bound
25             {
26 18     18   31 my ( $self, $bigint, $max ) = @_;
27              
28 18         26 return ( $bigint % $max );
29             }
30              
31             sub _private_max_random
32             {
33 18     18   26 my ( $obj, $max ) = @_;
34              
35 18         29 my $bigint = scalar( $obj->rand() );
36 18         29 my $result = scalar( $obj->_custom_bound( $bigint, $max ) );
37              
38 18         26 return $result;
39             }
40              
41             sub max_rand
42             {
43 18     18 1 29 my ( $obj, $max ) = @_;
44              
45 18         27 my $result = $obj->_private_max_random( $max, );
46              
47 18         28 return $result;
48             }
49              
50              
51             1; # End of Math::RNG::Microsoft
52              
53             __END__