| 1 | # Filename: Rand/MersenneTwister.pm | ||||||||||||||||||||
| 2 | # Author: George Schlossnagle <george@omniti.com> | ||||||||||||||||||||
| 3 | # Theo Schlossnagle <jesus@omniti.com> | ||||||||||||||||||||
| 4 | # Created: 03 October 2002 | ||||||||||||||||||||
| 5 | # Version: 1.0.1 | ||||||||||||||||||||
| 6 | # | ||||||||||||||||||||
| 7 | # Copyright (c) OmniTI Computer Consulting, Inc. All rights reserved. | ||||||||||||||||||||
| 8 | # This program is free software; you can redistribute it and/or | ||||||||||||||||||||
| 9 | # modify it under the same terms as Perl itself. | ||||||||||||||||||||
| 10 | # | ||||||||||||||||||||
| 11 | # | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | package Rand::MersenneTwister; | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 1 | require 5.004; | |||||||||||||||||||
| 16 | 1 | require Exporter; | |||||||||||||||||||
| 17 | 1 | require DynaLoader; | |||||||||||||||||||
| 18 | 1 | require AutoLoader; | |||||||||||||||||||
| 19 | 1 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | 1 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $AUTOLOAD); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 1 | $VERSION = "1.0.1" ; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 1 | @ISA = qw(Exporter DynaLoader); | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 1 | %EXPORT_TAGS = ( | |||||||||||||||||||
| 30 | FUNCS => [ qw(mt_init | ||||||||||||||||||||
| 31 | mt_free | ||||||||||||||||||||
| 32 | mt_seed | ||||||||||||||||||||
| 33 | mt_rand) ], | ||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 1 | @EXPORT = qw( ERROR ); | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 1 | @EXPORT_OK = qw( | |||||||||||||||||||
| 39 | mt_init | ||||||||||||||||||||
| 40 | mt_free | ||||||||||||||||||||
| 41 | mt_seed | ||||||||||||||||||||
| 42 | mt_rand); | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 45 | # This AUTOLOAD is used to 'autoload' constants from the constant() | ||||||||||||||||||||
| 46 | # XS function. If a constant is not found then control is passed | ||||||||||||||||||||
| 47 | # to the AUTOLOAD in AutoLoader. | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 0 | my $constname; | |||||||||||||||||||
| 50 | 0 | ($constname = $AUTOLOAD) =~ s/.*:://; | |||||||||||||||||||
| 51 | 0 | ▶ | my $val = constant($constname, @_ ? $_[0] : 0); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 0 | ▶ | if ($! != 0) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | 0 | ▶ | if ($! =~ /Invalid/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | 0 | $AutoLoader::AUTOLOAD = $AUTOLOAD; | |||||||||||||||||||
| 55 | 0 | goto &AutoLoader::AUTOLOAD; | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | else { | ||||||||||||||||||||
| 58 | 0 | croak "Your vendor has not defined Rand::MersenneTwister macro $constname"; | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | 0 | eval "sub $AUTOLOAD { \"$val\" }"; | |||||||||||||||||||
| 62 | 0 | goto &$AUTOLOAD; | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 1 | bootstrap Rand::MersenneTwister $VERSION ; | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 1 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||
| 68 | 1 | my $self = shift; | |||||||||||||||||||
| 69 | 1 | ▶ | my $class = ref($self) || $self; | ||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 1 | my $td = mt_init(); | |||||||||||||||||||
| 72 | 1 | my $obj = bless { GEN => $td }, $class; | |||||||||||||||||||
| 73 | 1 | ▶ | if(@_) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | 0 | $obj->seed(@_); | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | 1 | return $obj; | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 2 | ▶ | sub seed { | ||||||||||||||||||
|
Subroutine
seed: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||
| 80 | 2 | my($self, $seed) = @_; | |||||||||||||||||||
| 81 | 2 | ▶ | $seed ||= time*$$*100000; | ||||||||||||||||||
|
Condition33%1/3
$seed ||= time * $$ * 100000
MC/DC0%0/2
$seed ||= time * $$ * 100000
$seed
time * $$ * 100000
Truth table33%1/3
A ||= B
A= $seedB= time * $$ * 100000
| |||||||||||||||||||||
| 82 | 2 | mt_seed($self->{GEN}, $seed); | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 20 | ▶ | sub rand { | ||||||||||||||||||
|
Subroutine
rand: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 86 | 20 | my $self = shift; | |||||||||||||||||||
| 87 | 20 | return mt_rand($self->{GEN}, @_); | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 1 | ▶ | sub DESTROY { | ||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 91 | 1 | my($self) = shift; | |||||||||||||||||||
| 92 | 1 | mt_free($self->{GEN}); | |||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 1 | 1; | |||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | __END__ | ||||||||||||||||||||