Math-Random-OO-0.22/000755 000765 000024 00000000000 12155151164 014312 5ustar00davidstaff000000 000000 Math-Random-OO-0.22/Changes000644 000765 000024 00000003263 12155151164 015611 0ustar00davidstaff000000 000000 Revision history for Perl module Math::Random::OO 0.22 2013-06-09 15:07:27 America/New_York - Removed useless voodoo math [RT#85314] - Fixed test bug with negative seeds [RT#86002] - Converted to Dist::Zilla - Changed license to Apache 2 - Changed bugtracker 0.21 Sat May 2 07:40:03 EDT 2009 - Fixed major seed() bug (RT#45630) 0.20 Fri Jul 21 08:00:34 EDT 2006 - Cleaned up pod coverage test 0.19 Fri Jul 21 07:00:34 EDT 2006 - Whee! Added back pod/coverage tests in a sane way. 0.18 Fri Dec 16 13:20:26 EST 2005 - really remove Test::Exception as a dependency 0.17 Thu Dec 15 01:39:14 EST 2005 - added missing Class::Accessor::Fast dependency to Build.PL - removed Test::Exception and Attribute::Util dependencies from tests and code 0.16 Mon Aug 1 11:10:28 EDT 2005 - build_requires moved to requires to work around CPANPLUS bug 0.15 Thu Jun 9 15:59:11 EDT 2005 - removed pod/podcoverage/distribution tests to minimize dependencies 0.14 Tue Jun 7 18:10:09 EDT 2005 - fixed dependencies in Build.PL - changed Makefile compatibility 0.13 Wed Mar 9 06:30:16 EST 2005 - added pod and pod coverage testing 0.12 Wed Feb 2 22:50:30 EST 2005 - fixed test suite for new version of Test::MockRandom - improved test coverage 0.11 Tue Jan 4 07:20:38 EST 2005 - Fixed POD for better hyperlinking on CPAN - Refactored tests - Added Test::Distribution to automated tests (but not required for users) - Replaced Test::Float with Test::Number::Delta 0.10 Tue Dec 28 12:22:04 EST 2004 - initial public release 0.01 Tue Dec 14 13:36:52 2004 - original version; created by ExtUtils::ModuleMaker::TT Math-Random-OO-0.22/CONTRIBUTING000644 000765 000024 00000003254 12155151164 016150 0ustar00davidstaff000000 000000 CONTRIBUTING Thank you for considering contributing to this distribution. This file contains instructions that will help you work with the source code. The distribution is managed with Dist::Zilla. This means than many of the usual files you might expect are not in the repository, but are generated at release time (e.g. Makefile.PL). However, you can run tests directly using the 'prove' tool: $ prove -l $ prove -lv t/some_test_file.t For most distributions, 'prove' is entirely sufficent for you to test any patches you have. You may need to satisfy some dependencies. See the included META.json file for a list. If you install App::mymeta_requires from CPAN, it's easy to satisfy any that you are missing by piping the output to your favorite CPAN client: $ mymeta-requires | cpanm $ cpan `mymeta-requires` Likewise, much of the documentation Pod is generated at release time. Depending on the distribution, some documentation may be written in a Pod dialect called WikiDoc. (See Pod::WikiDoc on CPAN.) If you would like to submit a documentation edit, please limit yourself to the documentation you see. If you see typos or documentation issues in the generated docs, please email or open a bug ticket instead of patching. Dist::Zilla is a very powerful authoring tool, but requires a number of author-specific plugins. If you would like to use it for contributing, install it from CPAN, then run one of the following commands, depending on your CPAN client: $ cpan `dzil authordeps` $ dzil authordeps | cpanm Once installed, here are some dzil commands you might try: $ dzil build $ dzil test $ dzil xtest You can learn more about Dist::Zilla at http://dzil.org/ Math-Random-OO-0.22/dist.ini000644 000765 000024 00000000615 12155151164 015760 0ustar00davidstaff000000 000000 name = Math-Random-OO author = David Golden license = Apache_2_0 copyright_holder = David Golden [@DAGOLDEN] :version = 0.045 AutoMetaResources.bugtracker.rt = 0 AutoMetaResources.bugtracker.github = user:dagolden stopwords = Acklam stopwords = Mersenne stopwords = PRNG stopwords = drand stopwords = normals stopwords = parameteric stopwords = randlib stopwords = resampling Math-Random-OO-0.22/lib/000755 000765 000024 00000000000 12155151164 015060 5ustar00davidstaff000000 000000 Math-Random-OO-0.22/LICENSE000644 000765 000024 00000026354 12155151164 015331 0ustar00davidstaff000000 000000 This software is Copyright (c) 2013 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Math-Random-OO-0.22/Makefile.PL000644 000765 000024 00000003360 12155151164 016266 0ustar00davidstaff000000 000000 use strict; use warnings; use 5.006; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "Consistent object-oriented interface for generating random numbers", "AUTHOR" => "David Golden ", "BUILD_REQUIRES" => {}, "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "Math-Random-OO", "EXE_FILES" => [], "LICENSE" => "apache", "NAME" => "Math::Random::OO", "PREREQ_PM" => { "Carp" => 0, "Class::Accessor::Fast" => 0, "Params::Validate" => "0.76", "base" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "ExtUtils::MakeMaker" => 0, "File::Find" => 0, "File::Spec::Functions" => 0, "File::Temp" => 0, "List::Util" => 0, "Test::MockRandom" => "0.95", "Test::More" => 0, "Test::Number::Delta" => "0.14", "blib" => 0 }, "VERSION" => "0.22", "test" => { "TESTS" => "t/*.t" } ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { my $tr = delete $WriteMakefileArgs{TEST_REQUIRES}; my $br = $WriteMakefileArgs{BUILD_REQUIRES}; for my $mod ( keys %$tr ) { if ( exists $br->{$mod} ) { $br->{$mod} = $tr->{$mod} if $tr->{$mod} > $br->{$mod}; } else { $br->{$mod} = $tr->{$mod}; } } } unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) { my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; my $pp = $WriteMakefileArgs{PREREQ_PM}; for my $mod ( keys %$br ) { if ( exists $pp->{$mod} ) { $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; } else { $pp->{$mod} = $br->{$mod}; } } } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); Math-Random-OO-0.22/MANIFEST000644 000765 000024 00000001160 12155151164 015441 0ustar00davidstaff000000 000000 CONTRIBUTING Changes LICENSE MANIFEST META.json META.yml Makefile.PL README Todo dist.ini lib/Math/Random/OO.pm lib/Math/Random/OO/Bootstrap.pm lib/Math/Random/OO/Normal.pm lib/Math/Random/OO/Uniform.pm lib/Math/Random/OO/UniformInt.pm perlcritic.rc t/00-compile.t t/00-report-prereqs.t t/01-OO.t t/02-Uniform.t t/03-UniformInt.t t/04-Normal.t t/06-Bootstrap.t t/50-factory-function.t t/60-seeding.t t/98_pod.t t/99_pod_coverage.t xt/author/critic.t xt/author/pod-spell.t xt/release/distmeta.t xt/release/minimum-version.t xt/release/pod-coverage.t xt/release/pod-syntax.t xt/release/portability.t xt/release/test-version.t Math-Random-OO-0.22/META.json000644 000765 000024 00000005236 12155151164 015741 0ustar00davidstaff000000 000000 { "abstract" : "Consistent object-oriented interface for generating random numbers", "author" : [ "David Golden " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 4.300034, CPAN::Meta::Converter version 2.131560", "license" : [ "apache_2_0" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Math-Random-OO", "no_index" : { "directory" : [ "t", "xt", "examples", "corpus" ], "package" : [ "DB" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.30" } }, "develop" : { "requires" : { "Pod::Coverage::TrustPod" : "0", "Test::CPAN::Meta" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08" } }, "runtime" : { "requires" : { "Carp" : "0", "Class::Accessor::Fast" : "0", "Params::Validate" : "0.76", "base" : "0", "perl" : "5.006", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "ExtUtils::MakeMaker" : "0", "File::Find" : "0", "File::Spec::Functions" : "0", "File::Temp" : "0", "List::Util" : "0", "Test::MockRandom" : "0.95", "Test::More" : "0", "Test::Number::Delta" : "0.14", "blib" : "0" } } }, "provides" : { "Math::Random::OO" : { "file" : "lib/Math/Random/OO.pm", "version" : "0.22" }, "Math::Random::OO::Bootstrap" : { "file" : "lib/Math/Random/OO/Bootstrap.pm", "version" : "0.22" }, "Math::Random::OO::Normal" : { "file" : "lib/Math/Random/OO/Normal.pm", "version" : "0.22" }, "Math::Random::OO::Uniform" : { "file" : "lib/Math/Random/OO/Uniform.pm", "version" : "0.22" }, "Math::Random::OO::UniformInt" : { "file" : "lib/Math/Random/OO/UniformInt.pm", "version" : "0.22" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/dagolden/math-random-oo/issues" }, "homepage" : "https://metacpan.org/release/Math-Random-OO", "repository" : { "type" : "git", "url" : "git://github.com/dagolden/math-random-oo.git", "web" : "https://github.com/dagolden/math-random-oo" } }, "version" : "0.22" } Math-Random-OO-0.22/META.yml000644 000765 000024 00000002654 12155151164 015572 0ustar00davidstaff000000 000000 --- abstract: 'Consistent object-oriented interface for generating random numbers' author: - 'David Golden ' build_requires: ExtUtils::MakeMaker: 0 File::Find: 0 File::Spec::Functions: 0 File::Temp: 0 List::Util: 0 Test::MockRandom: 0.95 Test::More: 0 Test::Number::Delta: 0.14 blib: 0 configure_requires: ExtUtils::MakeMaker: 6.30 dynamic_config: 0 generated_by: 'Dist::Zilla version 4.300034, CPAN::Meta::Converter version 2.131560' license: apache meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Math-Random-OO no_index: directory: - t - xt - examples - corpus package: - DB provides: Math::Random::OO: file: lib/Math/Random/OO.pm version: 0.22 Math::Random::OO::Bootstrap: file: lib/Math/Random/OO/Bootstrap.pm version: 0.22 Math::Random::OO::Normal: file: lib/Math/Random/OO/Normal.pm version: 0.22 Math::Random::OO::Uniform: file: lib/Math/Random/OO/Uniform.pm version: 0.22 Math::Random::OO::UniformInt: file: lib/Math/Random/OO/UniformInt.pm version: 0.22 requires: Carp: 0 Class::Accessor::Fast: 0 Params::Validate: 0.76 base: 0 perl: 5.006 strict: 0 warnings: 0 resources: bugtracker: https://github.com/dagolden/math-random-oo/issues homepage: https://metacpan.org/release/Math-Random-OO repository: git://github.com/dagolden/math-random-oo.git version: 0.22 Math-Random-OO-0.22/perlcritic.rc000644 000765 000024 00000001072 12155151164 017000 0ustar00davidstaff000000 000000 severity = 5 verbose = 8 [Variables::ProhibitPunctuationVars] allow = $@ $! [TestingAndDebugging::ProhibitNoStrict] allow = refs # Turn these off [-BuiltinFunctions::ProhibitStringyEval] [-ControlStructures::ProhibitPostfixControls] [-ControlStructures::ProhibitUnlessBlocks] [-Documentation::RequirePodSections] [-InputOutput::ProhibitInteractiveTest] [-References::ProhibitDoubleSigils] [-RegularExpressions::RequireExtendedFormatting] [-InputOutput::ProhibitTwoArgOpen] [-Modules::ProhibitEvilModules] # Turn this on [Lax::ProhibitStringyEval::ExceptForRequire] Math-Random-OO-0.22/README000644 000765 000024 00000012020 12155151164 015165 0ustar00davidstaff000000 000000 NAME Math::Random::OO - Consistent object-oriented interface for generating random numbers VERSION version 0.22 SYNOPSIS # Using factory functions use Math::Random::OO qw( Uniform UniformInt ); push @prngs, Uniform(), UniformInt(1,6); # Explicit creation of subclasses use Math::Random::OO::Normal; push @prngs, Math::Random::OO::Normal->new(0,2); $_->seed(23) for (@prngs); print( $_->next(), "\n") for (@prngs); DESCRIPTION CPAN contains many modules for generating random numbers in various ways and from various probability distributions using pseudo-random number generation algorithms or other entropy sources. (The "SEE ALSO" section has some examples.) Unfortunately, no standard interface exists across these modules. This module defines an abstract interface for random number generation. Subclasses of this model will implement specific types of random number generators or will wrap existing random number generators. This consistency will come at the cost of some efficiency, but will enable generic routines to be written that can manipulate any provided random number generator that adheres to the interface. E.g., a stochastic simulation could take a number of user-supplied parameters, each of which is a Math::Random::OO subclass object and which represent a stochastic variable with a particular probability distribution. USAGE Factory Functions use Math::Random::OO qw( Uniform UniformInt Normal Bootstrap ); $uniform = Uniform(-1,1); $uni_int = UniformInt(1,6); $normal = Normal(1,1); $boot = Bootstrap( 2, 3, 3, 4, 4, 4, 5, 5, 5 ); In addition to defining the abstract interface for subclasses, this module imports subclasses and exports factory functions upon request to simplify creating many random number generators at once without typing "Math::Random::OO::Subclass->new()" each time. The factory function names are the same as the suffix of the subclass following "Math::Random::OO". When called, they pass their arguments directly to the "new" constructor method of the corresponding subclass and return a new object of the subclass type. Supported functions and their subclasses include: * "Uniform" -- Math::Random::OO::Uniform (uniform distribution over a range) * "UniformInt" -- Math::Random::OO::UniformInt (uniform distribution of integers over a range) * "Normal" -- Math::Random::OO::Normal (normal distribution with specified mean and standard deviation) * "Bootstrap" -- Math::Random::OO::Bootstrap (bootstrap resampling from a non-parameteric distribution) INTERFACE All Math::Random::OO subclasses must follow a standard interface. They must provide a "new" method, a "seed" method, and a "next" method. Specific details are left to each interface. "new" This is the standard constructor. Each subclass will define parameters specific to the subclass. "seed" $prng->seed( @seeds ); This method takes seed (or list of seeds) and uses it to set the initial state of the random number generator. As some subclasses may optionally use/require a list of seeds, the interface mandates that a list must be acceptable. Generators requiring a single seed must use the first value in the list. As seeds may be passed to the built-in "srand()" function, they may be truncated as integers, so 0.12 and 0.34 would be the same seed. Only positive integers should be used. "next" $rnd = $prng->next(); This method returns the next random number from the random number generator. It does not take (and must not use) any parameters. SEE ALSO This is not an exhaustive list -- search CPAN for that -- but represents some of the more common or established random number generators that I've come across. Math::Random -- multiple random number generators for different distributions (a port of the C randlib) Math::Rand48 -- perl bindings for the drand48 library (according to perl56delta, this may already be the default after perl 5.005_52 if available) Math::Random::MT -- The Mersenne Twister PRNG (good and fast) Math::TrulyRandom -- an interface to random numbers from interrupt timing discrepancies SUPPORT Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at . You will be notified automatically of any progress on your issue. Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. git clone git://github.com/dagolden/math-random-oo.git AUTHOR David Golden COPYRIGHT AND LICENSE This software is Copyright (c) 2013 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 Math-Random-OO-0.22/t/000755 000765 000024 00000000000 12155151164 014555 5ustar00davidstaff000000 000000 Math-Random-OO-0.22/Todo000644 000765 000024 00000000744 12155151164 015147 0ustar00davidstaff000000 000000 TODO list for Perl module Math::Random::OO Next release: - test for require errors in import() - improve test coverage Near term: - Rewrite M::R::OO to support use of M::R::TT as a base random function for all submodules. (use Math::Random::OO prng => 'Math::Random::TT';) - Benchmark speed - Document modules - Review Devel::Cover output and increase test coverage Long term: - Write Triangle - Decide on other distributions to create (e.g. LogNormal) - Correlated Normals Math-Random-OO-0.22/xt/000755 000765 000024 00000000000 12155151164 014745 5ustar00davidstaff000000 000000 Math-Random-OO-0.22/xt/author/000755 000765 000024 00000000000 12155151164 016247 5ustar00davidstaff000000 000000 Math-Random-OO-0.22/xt/release/000755 000765 000024 00000000000 12155151164 016365 5ustar00davidstaff000000 000000 Math-Random-OO-0.22/xt/release/distmeta.t000644 000765 000024 00000000217 12155151164 020364 0ustar00davidstaff000000 000000 #!perl use Test::More; eval "use Test::CPAN::Meta"; plan skip_all => "Test::CPAN::Meta required for testing META.yml" if $@; meta_yaml_ok(); Math-Random-OO-0.22/xt/release/minimum-version.t000644 000765 000024 00000000266 12155151164 021714 0ustar00davidstaff000000 000000 #!perl use Test::More; eval "use Test::MinimumVersion"; plan skip_all => "Test::MinimumVersion required for testing minimum versions" if $@; all_minimum_version_ok( qq{5.010} ); Math-Random-OO-0.22/xt/release/pod-coverage.t000644 000765 000024 00000000527 12155151164 021131 0ustar00davidstaff000000 000000 #!perl use Test::More; eval "use Test::Pod::Coverage 1.08"; plan skip_all => "Test::Pod::Coverage 1.08 required for testing POD coverage" if $@; eval "use Pod::Coverage::TrustPod"; plan skip_all => "Pod::Coverage::TrustPod required for testing POD coverage" if $@; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); Math-Random-OO-0.22/xt/release/pod-syntax.t000644 000765 000024 00000000212 12155151164 020653 0ustar00davidstaff000000 000000 #!perl use Test::More; eval "use Test::Pod 1.41"; plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; all_pod_files_ok(); Math-Random-OO-0.22/xt/release/portability.t000644 000765 000024 00000000332 12155151164 021112 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More; eval 'use Test::Portability::Files'; plan skip_all => 'Test::Portability::Files required for testing portability' if $@; options(test_one_dot => 0); run_tests(); Math-Random-OO-0.22/xt/release/test-version.t000644 000765 000024 00000000643 12155151164 021217 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::Version 0.002004 BEGIN { eval "use Test::Version; 1;" or die $@; } my @imports = ( 'version_all_ok' ); my $params = { is_strict => 0, has_version => 1, }; push @imports, $params if version->parse( $Test::Version::VERSION ) >= version->parse('1.002'); Test::Version->import(@imports); version_all_ok; done_testing; Math-Random-OO-0.22/xt/author/critic.t000644 000765 000024 00000000435 12155151164 017713 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More; use English qw(-no_match_vars); eval "use Test::Perl::Critic"; plan skip_all => 'Test::Perl::Critic required to criticise code' if $@; Test::Perl::Critic->import( -profile => "perlcritic.rc" ) if -e "perlcritic.rc"; all_critic_ok(); Math-Random-OO-0.22/xt/author/pod-spell.t000644 000765 000024 00000000622 12155151164 020333 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::PodSpelling 2.006000 eval "use Test::Spelling 0.12; use Pod::Wordlist::hanekomu; 1" or die $@; add_stopwords(); all_pod_files_spelling_ok( qw( bin lib ) ); __DATA__ Acklam Mersenne PRNG drand normals parameteric randlib resampling David Golden dagolden lib Math Random OO Uniform Normal UniformInt Bootstrap Math-Random-OO-0.22/t/00-compile.t000644 000765 000024 00000003100 12155151164 016601 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More; use File::Find; use File::Temp qw{ tempdir }; my @modules; find( sub { return if $File::Find::name !~ /\.pm\z/; my $found = $File::Find::name; $found =~ s{^lib/}{}; $found =~ s{[/\\]}{::}g; $found =~ s/\.pm$//; # nothing to skip push @modules, $found; }, 'lib', ); sub _find_scripts { my $dir = shift @_; my @found_scripts = (); find( sub { return unless -f; my $found = $File::Find::name; # nothing to skip open my $FH, '<', $_ or do { note( "Unable to open $found in ( $! ), skipping" ); return; }; my $shebang = <$FH>; return unless $shebang =~ /^#!.*?\bperl\b\s*$/; push @found_scripts, $found; }, $dir, ); return @found_scripts; } my @scripts; do { push @scripts, _find_scripts($_) if -d $_ } for qw{ bin script scripts }; my $plan = scalar(@modules) + scalar(@scripts); $plan ? (plan tests => $plan) : (plan skip_all => "no tests to run"); { # fake home for cpan-testers local $ENV{HOME} = tempdir( CLEANUP => 1 ); like( qx{ $^X -Ilib -e "require $_; print '$_ ok'" }, qr/^\s*$_ ok/s, "$_ loaded ok" ) for sort @modules; SKIP: { eval "use Test::Script 1.05; 1;"; skip "Test::Script needed to test script compilation", scalar(@scripts) if $@; foreach my $file ( @scripts ) { my $script = $file; $script =~ s!.*/!!; script_compiles( $file, "$script script compiles" ); } } } Math-Random-OO-0.22/t/00-report-prereqs.t000644 000765 000024 00000003170 12155151164 020152 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec::Functions; use List::Util qw/max/; my @modules = qw( Carp Class::Accessor::Fast ExtUtils::MakeMaker File::Find File::Spec::Functions File::Temp List::Util Params::Validate Test::MockRandom Test::More Test::Number::Delta base blib perl strict warnings ); # replace modules with dynamic results from MYMETA.json if we can # (hide CPAN::Meta from prereq scanner) my $cpan_meta = "CPAN::Meta"; if ( -f "MYMETA.json" && eval "require $cpan_meta" ) { ## no critic if ( my $meta = eval { CPAN::Meta->load_file("MYMETA.json") } ) { my $prereqs = $meta->prereqs; delete $prereqs->{develop}; my %uniq = map {$_ => 1} map { keys %$_ } map { values %$_ } values %$prereqs; $uniq{$_} = 1 for @modules; # don't lose any static ones @modules = sort keys %uniq; } } my @reports = [qw/Version Module/]; for my $mod ( @modules ) { next if $mod eq 'perl'; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e catfile($_, $file) } @INC; if ( $prefix ) { my $ver = MM->parse_version( catfile($prefix, $file) ); $ver = "undef" unless defined $ver; # Newer MM should do this anyway push @reports, [$ver, $mod]; } else { push @reports, ["missing", $mod]; } } if ( @reports ) { my $vl = max map { length $_->[0] } @reports; my $ml = max map { length $_->[1] } @reports; splice @reports, 1, 0, ["-" x $vl, "-" x $ml]; diag "Prerequisite Report:\n", map {sprintf(" %*s %*s\n",$vl,$_->[0],-$ml,$_->[1])} @reports; } pass; # vim: ts=2 sts=2 sw=2 et: Math-Random-OO-0.22/t/01-OO.t000644 000765 000024 00000000651 12155151164 015477 0ustar00davidstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use blib; # Math::Random::OO use Test::More tests => 6 ; BEGIN { use_ok( 'Math::Random::OO' ); } my $obj = Math::Random::OO->new (); isa_ok ($obj, 'Math::Random::OO'); isa_ok ($obj->new, 'Math::Random::OO'); can_ok ($obj, qw( seed next ) ); eval { $obj->seed() }; ok( $@, 'does seed abstract method die?' ); eval { $obj->next() }; ok( $@, 'does next abstract method die?'); Math-Random-OO-0.22/t/02-Uniform.t000644 000765 000024 00000003417 12155151164 016605 0ustar00davidstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use blib; # Math::Random::OO::Uniform my ($test_array, $test_program); BEGIN { $test_array = [ { new_args => [], data => [ [0.5, 0.5], [0.23, 0.23] ] }, { new_args => [2], data => [ [0.4, 0.8], [0.7, 1.4] ] }, { new_args => [1, 6], data => [ [0.5, 3.5], [0.1, 1.5] ] }, { new_args => [-1, 1], data => [ [0.5, 0], [0.6, 0.2] ] }, { new_args => [2,-2], data => [ [0.5, 0], [0.6, 0.4] ] }, ]; $test_program = 0; $test_program += @{$_->{data}} + 1 for @$test_array; } use Test::More tests => (4 + $test_program); use Test::Number::Delta 0.14 within => 1e-5; use Test::MockRandom 0.95 'Math::Random::OO::Uniform'; BEGIN { Test::MockRandom->export_srand_to('Math::Random::OO::Uniform') } BEGIN { use_ok( 'Math::Random::OO::Uniform' ); } my $obj = Math::Random::OO::Uniform->new (); isa_ok ($obj, 'Math::Random::OO::Uniform'); isa_ok ($obj->new, 'Math::Random::OO::Uniform'); can_ok ($obj, qw( seed next )); for my $case ( @$test_array ) { ok( $obj = $obj->new(@{$case->{new_args}}), 'creating object with new('.join(", ",@{$case->{new_args}}).')'); for my $data (@{$case->{data}}) { my ($seed,$val) = @$data; $obj->seed($seed); delta_ok( $obj->next, $val, "does srand($seed),next() give $val?" ); } } Math-Random-OO-0.22/t/03-UniformInt.t000644 000765 000024 00000004356 12155151164 017264 0ustar00davidstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use blib; # Math::Random::OO::UniformInt my ($test_array, $test_program); BEGIN { $test_array = [ { new_args => [], data => [ [0.2, 0], [0.5, 1], ] }, { new_args => [1], data => [ [0.4, 0], [0.5, 1], ] }, { new_args => [2], data => [ [0.25, 0], [0.34, 1], [0.67, 2] ] }, { new_args => [1, 6], data => [ [0.1, 1], [0.3, 2], [0.5, 4], [0.7, 5] ] }, { new_args => [-1, 1], data => [ [0.33, -1], [0.34, 0], [0.67, 1] ] }, { new_args => [1,-1], data => [ [0.33, -1], [0.34, 0], [0.67, 1] ] }, { new_args => [-1.56,1.23], data => [ [0.33, -1], [0.34, 0], [0.67, 1] ] }, ]; $test_program = 0; $test_program += @{$_->{data}} + 1 for @$test_array; } use Test::More tests => (4 + $test_program); use Test::Number::Delta within => 1e-5; use Test::MockRandom 'Math::Random::OO::UniformInt'; BEGIN { Test::MockRandom->export_srand_to('Math::Random::OO::UniformInt') } BEGIN { use_ok( 'Math::Random::OO::UniformInt' ); } my $obj = Math::Random::OO::UniformInt->new (); isa_ok ($obj, 'Math::Random::OO::UniformInt'); isa_ok ($obj->new, 'Math::Random::OO::UniformInt'); can_ok ($obj, qw( seed next )); for my $case ( @$test_array ) { ok( $obj = $obj->new(@{$case->{new_args}}), 'creating object with new('.join(", ",@{$case->{new_args}}).')'); for my $data (@{$case->{data}}) { my ($seed,$val) = @$data; $obj->seed($seed); delta_ok( $obj->next, $val, "does srand($seed),next() give $val?" ); } } Math-Random-OO-0.22/t/04-Normal.t000644 000765 000024 00000003514 12155151164 016416 0ustar00davidstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use blib; # Math::Random::OO::Normal my ($test_array, $test_program); BEGIN { $test_array = [ { new_args => [], data => [ [0.5, 0], [0.3, -0.52440], [0.9, 1.28155], [0.1, -1.28155] ] }, { new_args => [5], data => [ [0.5, 5], [0.3, 4.47560], [0.9, 6.28155] ] }, { new_args => [0,3], data => [ [0.5, 0], [0.3, -1.57320], [0.9, 3.84465] ] }, { new_args => [0,-3], data => [ [0.5, 0], [0.3, -1.57320], [0.9, 3.84465] ] }, ]; $test_program = 0; $test_program += @{$_->{data}} + 1 for @$test_array; } use Test::More tests => (5 + $test_program); use Test::Number::Delta within => 1e-5; use Test::MockRandom 'Math::Random::OO::Normal'; BEGIN { Test::MockRandom->export_srand_to('Math::Random::OO::Normal') } BEGIN { use_ok( 'Math::Random::OO::Normal' ); } my $obj = Math::Random::OO::Normal->new (); isa_ok ($obj, 'Math::Random::OO::Normal'); isa_ok ($obj->new, 'Math::Random::OO::Normal'); can_ok ($obj, qw( seed next )); eval { $obj->next }; is( $@, "", 'next handles 0 correctly?'); for my $case ( @$test_array ) { ok( $obj = $obj->new(@{$case->{new_args}}), 'creating object with new('.join(", ",@{$case->{new_args}}).')'); for my $data (@{$case->{data}}) { my ($seed,$val) = @$data; $obj->seed($seed); delta_ok( $obj->next, $val, "does srand($seed),next() give $val?" ); } } Math-Random-OO-0.22/t/06-Bootstrap.t000644 000765 000024 00000003052 12155151164 017142 0ustar00davidstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use blib; # Math::Random::OO::Bootstrap use Test::MockRandom 'Math::Random::OO::Bootstrap'; BEGIN { Test::MockRandom->export_srand_to('Math::Random::OO::Bootstrap') } my ($test_array, $test_program); BEGIN { $test_array = [ { name => "list", new_args => [ 1, 2, 2, 3 ], data => [ [0.2, 1], [0.5, 2], [oneish, 3] ] }, { name => "arrayref", new_args => [ [1, 2, 2, 3 ] ], data => [ [0.2, 1], [0.5, 2], [oneish, 3] ] }, ]; $test_program = 0; $test_program += @{$_->{data}} + 1 for @$test_array; } use Test::More tests => (5 + $test_program); use Test::Number::Delta within => 1e-5; BEGIN { use_ok( 'Math::Random::OO::Bootstrap' ); } my $obj; eval { Math::Random::OO::Bootstrap->new() }; ok( $@, 'does new die with no arguments?' ); $obj = Math::Random::OO::Bootstrap->new(1); isa_ok ($obj, 'Math::Random::OO::Bootstrap'); isa_ok ($obj->new(1), 'Math::Random::OO::Bootstrap'); can_ok ($obj, qw( seed next )); for my $case ( @$test_array ) { ok( $obj = $obj->new(@{$case->{new_args}}), 'creating object with '.$case->{name}.' args to new()'); for my $data (@{$case->{data}}) { my ($seed,$val) = @$data; $obj->seed($seed); delta_ok( $obj->next, $val, "does srand($seed),next() give $val?" ); } } Math-Random-OO-0.22/t/50-factory-function.t000755 000765 000024 00000000551 12155151164 020462 0ustar00davidstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use blib; # Math::Random::OO use Test::More tests => 6; my @fcns; BEGIN { @fcns = qw (Uniform UniformInt Normal Bootstrap) } BEGIN { use_ok( 'Math::Random::OO', @fcns ); } can_ok( 'main', @fcns ); my $obj; for (@fcns) { no strict 'refs'; $obj = &{$_}(0,1); isa_ok( $obj, "Math::Random::OO::$_" ); } Math-Random-OO-0.22/t/60-seeding.t000755 000765 000024 00000001066 12155151164 016611 0ustar00davidstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use blib; # Math::Random::OO use Test::More 'no_plan'; my @classes = qw(Uniform UniformInt Normal); my @seeds = qw/ 0 1 2 3 /; for my $c (@classes) { $c = "Math::Random::OO::$c"; require_ok( $c ); my $rng = $c->new(); my @rands; for my $s ( @seeds ) { $rng->seed($s); push @rands, [ $s, [map { $rng->next } 1 .. 5] ]; } while ( my $first = shift @rands ) { for my $r ( @rands ) { ok( ! eq_array( $first->[1], $r->[1] ), "$c\: contents differ ($first->[0] vs $r->[0])" ); } } } Math-Random-OO-0.22/t/98_pod.t000644 000765 000024 00000000342 12155151164 016043 0ustar00davidstaff000000 000000 use Test::More; plan skip_all => "Skipping author tests" if not $ENV{AUTHOR_TESTING}; my $min_tp = 1.22; eval "use Test::Pod $min_tp"; plan skip_all => "Test::Pod $min_tp required for testing POD" if $@; all_pod_files_ok(); Math-Random-OO-0.22/t/99_pod_coverage.t000644 000765 000024 00000000625 12155151164 017723 0ustar00davidstaff000000 000000 use Test::More; plan skip_all => "Skipping author tests" if not $ENV{AUTHOR_TESTING}; my $min_tpc = 1.08; eval "use Test::Pod::Coverage $min_tpc"; plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage" if $@; my $min_pc = 0.17; eval "use Pod::Coverage $min_pc"; plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage" if $@; all_pod_coverage_ok(); Math-Random-OO-0.22/lib/Math/000755 000765 000024 00000000000 12155151164 015751 5ustar00davidstaff000000 000000 Math-Random-OO-0.22/lib/Math/Random/000755 000765 000024 00000000000 12155151164 017171 5ustar00davidstaff000000 000000 Math-Random-OO-0.22/lib/Math/Random/OO/000755 000765 000024 00000000000 12155151164 017506 5ustar00davidstaff000000 000000 Math-Random-OO-0.22/lib/Math/Random/OO.pm000644 000765 000024 00000013345 12155151164 020052 0ustar00davidstaff000000 000000 use 5.006; use strict; use warnings; package Math::Random::OO; # ABSTRACT: Consistent object-oriented interface for generating random numbers our $VERSION = '0.22'; # VERSION use Carp; sub import { my ( $class, @symbols ) = @_; my $caller = caller; for (@symbols) { no strict 'refs'; my $subclass = "Math::Random::OO::$_"; eval "require $subclass"; *{"${caller}::$_"} = sub { return ${subclass}->new(@_) }; } } sub new { my $class = shift; return bless( {}, ref($class) ? ref($class) : $class ); } sub seed { die "call to abstract method 'seed'" } sub next { die "call to abstract method 'next'" } 1; __END__ =pod =encoding utf-8 =head1 NAME Math::Random::OO - Consistent object-oriented interface for generating random numbers =head1 VERSION version 0.22 =head1 SYNOPSIS # Using factory functions use Math::Random::OO qw( Uniform UniformInt ); push @prngs, Uniform(), UniformInt(1,6); # Explicit creation of subclasses use Math::Random::OO::Normal; push @prngs, Math::Random::OO::Normal->new(0,2); $_->seed(23) for (@prngs); print( $_->next(), "\n") for (@prngs); =head1 DESCRIPTION CPAN contains many modules for generating random numbers in various ways and from various probability distributions using pseudo-random number generation algorithms or other entropy sources. (The L section has some examples.) Unfortunately, no standard interface exists across these modules. This module defines an abstract interface for random number generation. Subclasses of this model will implement specific types of random number generators or will wrap existing random number generators. This consistency will come at the cost of some efficiency, but will enable generic routines to be written that can manipulate any provided random number generator that adheres to the interface. E.g., a stochastic simulation could take a number of user-supplied parameters, each of which is a Math::Random::OO subclass object and which represent a stochastic variable with a particular probability distribution. =head1 USAGE =head2 Factory Functions use Math::Random::OO qw( Uniform UniformInt Normal Bootstrap ); $uniform = Uniform(-1,1); $uni_int = UniformInt(1,6); $normal = Normal(1,1); $boot = Bootstrap( 2, 3, 3, 4, 4, 4, 5, 5, 5 ); In addition to defining the abstract interface for subclasses, this module imports subclasses and exports factory functions upon request to simplify creating many random number generators at once without typing Cnew()> each time. The factory function names are the same as the suffix of the subclass following C. When called, they pass their arguments directly to the C constructor method of the corresponding subclass and return a new object of the subclass type. Supported functions and their subclasses include: =over =item * C -- L (uniform distribution over a range) =item * C -- L (uniform distribution of integers over a range) =item * C -- L (normal distribution with specified mean and standard deviation) =item * C -- L (bootstrap resampling from a non-parameteric distribution) =back =head1 INTERFACE All Math::Random::OO subclasses must follow a standard interface. They must provide a C method, a C method, and a C method. Specific details are left to each interface. =head2 C This is the standard constructor. Each subclass will define parameters specific to the subclass. =head2 C $prng->seed( @seeds ); This method takes seed (or list of seeds) and uses it to set the initial state of the random number generator. As some subclasses may optionally use/require a list of seeds, the interface mandates that a list must be acceptable. Generators requiring a single seed must use the first value in the list. As seeds may be passed to the built-in C function, they may be truncated as integers, so 0.12 and 0.34 would be the same seed. Only positive integers should be used. =head2 C $rnd = $prng->next(); This method returns the next random number from the random number generator. It does not take (and must not use) any parameters. =head1 SEE ALSO This is not an exhaustive list -- search CPAN for that -- but represents some of the more common or established random number generators that I've come across. =over =item L -- multiple random number generators for different distributions (a port of the C randlib) =item L -- perl bindings for the drand48 library (according to perl56delta, this may already be the default after perl 5.005_52 if available) =item L -- The Mersenne Twister PRNG (good and fast) =item L -- an interface to random numbers from interrupt timing discrepancies =back =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan =head1 SUPPORT =head2 Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at L. You will be notified automatically of any progress on your issue. =head2 Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. L git clone git://github.com/dagolden/math-random-oo.git =head1 AUTHOR David Golden =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2013 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 =cut Math-Random-OO-0.22/lib/Math/Random/OO/Bootstrap.pm000644 000765 000024 00000006165 12155151164 022031 0ustar00davidstaff000000 000000 use 5.006; use strict; use warnings; package Math::Random::OO::Bootstrap; # ABSTRACT: Generate random numbers with bootstrap resampling from a non-parametric distribution our $VERSION = '0.22'; # VERSION # Required modules use Carp; use Params::Validate 0.76 ':all'; # ISA use base qw( Class::Accessor::Fast ); { my $param_spec = { data => { type => ARRAYREF }, size => { type => SCALAR } }; __PACKAGE__->mk_accessors( keys %$param_spec ); #__PACKAGE__->mk_ro_accessors( keys %$param_spec ); sub new { my $class = shift; my $self = bless {}, ref($class) ? ref($class) : $class; if ( @_ == 0 ) { croak 'Math::Random::OO::Bootstrap->new() requires an argument'; } $self->data( ref $_[0] eq 'ARRAY' ? [ @{ $_[0] } ] : [@_] ); $self->size( scalar @{ $self->data } ); return $self; } } sub seed { my $self = shift; srand( $_[0] ); } sub next { my ($self) = @_; my $rnd = int( rand( $self->size ) ); # index 0 to (size-1) return $self->data->[$rnd]; } 1; __END__ =pod =encoding utf-8 =head1 NAME Math::Random::OO::Bootstrap - Generate random numbers with bootstrap resampling from a non-parametric distribution =head1 VERSION version 0.22 =head1 SYNOPSIS use Math::Random::OO::Bootstrap; @sample = qw( 2 3 3 4 4 5 5 6 6 7 ); $prng = Math::Random::OO::Bootstrap->new(@sample); $prng->seed(42); $prng->next() # draws randomly from the sample =head1 DESCRIPTION This subclass of L generates random numbers with bootstrap resampling (i.e. resampling with replacement) from a given set of observations. Each item in the sample array is drawn with equal probability. =head1 METHODS =head2 C $prng = Math::Random::OO::Bootstrap->new(@sample); $prng = Math::Random::OO::Bootstrap->new(\@sample); C takes either a list or a reference to an array containing a set of observations and returns a new C object. If a reference is provided, the object will make an internal copy of the array to avoid unexpected results if the source reference is modified. If the desired sample is an array of array references, the list must be enclosed in an anonymous array reference to avoid ambiguity. @sample = ( [ 1, 2, 3], [2, 3, 4] ); # Correct way $prng = Math::Random::OO::Bootstrap->new( [ @sample ] ); # Incorrect -- will only use [1, 2, 3] as the desired sample $prng = Math::Random::OO::Bootstrap->new( @sample ); It is an error to call C with no arguments. =head2 C $rv = $prng->seed( @seeds ); This method seeds the random number generator. At the moment, only the first seed value matters. It should be a positive integer. =head2 C $rnd = $prng->next(); This method returns the next random number from the random number generator by resampling with replacement from the provided data. It does not take any parameters. =head1 AUTHOR David Golden =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2013 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 =cut Math-Random-OO-0.22/lib/Math/Random/OO/Normal.pm000644 000765 000024 00000014177 12155151164 021306 0ustar00davidstaff000000 000000 use 5.006; use strict; use warnings; package Math::Random::OO::Normal; # ABSTRACT: Generates random numbers from the normal (Gaussian) distribution our $VERSION = '0.22'; # VERSION # Required modules use Carp; use Params::Validate ':all'; # ISA use base qw( Class::Accessor::Fast ); { my $param_spec = { mean => { type => SCALAR }, stdev => { type => SCALAR } }; __PACKAGE__->mk_accessors( keys %$param_spec ); #__PACKAGE__->mk_ro_accessors( keys %$param_spec ); sub new { my $class = shift; my $self = bless {}, ref($class) ? ref($class) : $class; if ( @_ > 1 ) { $self->mean( $_[0] ); $self->stdev( abs( $_[1] ) ); } elsif ( @_ == 1 ) { $self->mean( $_[0] ); $self->stdev(1); } else { $self->mean(0); $self->stdev(1); } return $self; } } sub seed { my $self = shift; srand( $_[0] ); } sub next { my ($self) = @_; my $rnd = rand() || 1e-254; # can't have zero for normals return _ltqnorm($rnd) * $self->stdev + $self->mean; } #--------------------------------------------------------------------------# # Function for inverse cumulative normal # Used with permission # http://home.online.no/~pjacklam/notes/invnorm/impl/acklam/perl/ # # Input checking removed by DAGOLDEN as the input will be prechecked #--------------------------------------------------------------------------# #<<< No perltidy sub _ltqnorm { # Lower tail quantile for standard normal distribution function. # # This function returns an approximation of the inverse cumulative # standard normal distribution function. I.e., given P, it returns # an approximation to the X satisfying P = Pr{Z <= X} where Z is a # random variable from the standard normal distribution. # # The algorithm uses a minimax approximation by rational functions # and the result has a relative error whose absolute value is less # than 1.15e-9. # # Author: Peter J. Acklam # Time-stamp: 2000-07-19 18:26:14 # E-mail: pjacklam@online.no # WWW URL: http://home.online.no/~pjacklam my $p = shift; # DAGOLDEN: arg checking will be done earlier # die "input argument must be in (0,1)\n" unless 0 < $p && $p < 1; # Coefficients in rational approximations. my @a = (-3.969683028665376e+01, 2.209460984245205e+02, -2.759285104469687e+02, 1.383577518672690e+02, -3.066479806614716e+01, 2.506628277459239e+00); my @b = (-5.447609879822406e+01, 1.615858368580409e+02, -1.556989798598866e+02, 6.680131188771972e+01, -1.328068155288572e+01 ); my @c = (-7.784894002430293e-03, -3.223964580411365e-01, -2.400758277161838e+00, -2.549732539343734e+00, 4.374664141464968e+00, 2.938163982698783e+00); my @d = ( 7.784695709041462e-03, 3.224671290700398e-01, 2.445134137142996e+00, 3.754408661907416e+00); # Define break-points. my $plow = 0.02425; my $phigh = 1 - $plow; # Rational approximation for lower region: if ( $p < $plow ) { my $q = sqrt(-2*log($p)); return ((((($c[0]*$q+$c[1])*$q+$c[2])*$q+$c[3])*$q+$c[4])*$q+$c[5]) / (((($d[0]*$q+$d[1])*$q+$d[2])*$q+$d[3])*$q+1); } # Rational approximation for upper region: if ( $phigh < $p ) { my $q = sqrt(-2*log(1-$p)); return -((((($c[0]*$q+$c[1])*$q+$c[2])*$q+$c[3])*$q+$c[4])*$q+$c[5]) / (((($d[0]*$q+$d[1])*$q+$d[2])*$q+$d[3])*$q+1); } # Rational approximation for central region: my $q = $p - 0.5; my $r = $q*$q; return ((((($a[0]*$r+$a[1])*$r+$a[2])*$r+$a[3])*$r+$a[4])*$r+$a[5])*$q / ((((($b[0]*$r+$b[1])*$r+$b[2])*$r+$b[3])*$r+$b[4])*$r+1); } #>>> 1; __END__ =pod =encoding utf-8 =head1 NAME Math::Random::OO::Normal - Generates random numbers from the normal (Gaussian) distribution =head1 VERSION version 0.22 =head1 SYNOPSIS use Math::Random::OO::Normal; push @prngs, Math::Random::OO::Normal->new(), # mean 0, stdev 1 Math::Random::OO::Normal->new(5), # mean 5, stdev 1 Math::Random::OO::Normal->new(1,3); # mean 1, stdev 3 $_->seed(42) for @prngs; print( $_->next() . "\n" ) for @prngs; =head1 DESCRIPTION This subclass of L generates random reals from the normal probability distribution, also called the Gaussian or bell-curve distribution. The module generates random normals from the inverse of the cumulative normal distribution using an approximation algorithm developed by Peter J. Acklam and released into the public domain. This algorithm claims a relative error of less than 1.15e-9 over the entire region. See http://home.online.no/~pjacklam/notes/invnorm/ for details and discussion. =head1 METHODS =head2 C $prng1 = Math::Random::OO::Normal->new(); $prng2 = Math::Random::OO::Normal->new($mean); $prng3 = Math::Random::OO::Normal->new($mean,$stdev); C takes up to two optional parameters and returns a new C object. With no parameters, the object generates random numbers from the standard normal distribution (mean zero, standard deviation one). With a single parameter, the object generates random numbers with mean equal to the parameter and standard deviation of one. With two parameters, the object generates random numbers with mean equal to the first parameter and standard deviation equal to the second parameter. (Standard deviation should be positive, but this module takes the absolute value of the parameter just in case.) =head2 C $rv = $prng->seed( @seeds ); This method seeds the random number generator. At the moment, only the first seed value matters. It should be a positive integer. =head2 C $rnd = $prng->next(); This method returns the next random number from the random number generator. It does not take any parameters. =head1 AUTHOR David Golden =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2013 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 =cut Math-Random-OO-0.22/lib/Math/Random/OO/Uniform.pm000644 000765 000024 00000006224 12155151164 021467 0ustar00davidstaff000000 000000 use 5.006; use strict; use warnings; package Math::Random::OO::Uniform; # ABSTRACT: Generates random numbers from the uniform distribution our $VERSION = '0.22'; # VERSION # Required modules use Carp; use Params::Validate ':all'; # ISA use base qw( Class::Accessor::Fast ); { my $param_spec = { low => { type => SCALAR }, high => { type => SCALAR } }; __PACKAGE__->mk_accessors( keys %$param_spec ); #__PACKAGE__->mk_ro_accessors( keys %$param_spec ); sub new { my $class = shift; my $self = bless {}, ref($class) ? ref($class) : $class; if ( @_ > 1 ) { my ( $low, $high ) = sort { $a <=> $b } @_[ 0, 1 ]; # DWIM $self->low($low); $self->high($high); } elsif ( @_ == 1 ) { $self->low(0); $self->high( $_[0] ); } else { $self->low(0); $self->high(0); } return $self; } } sub seed { my $self = shift; srand( $_[0] ); } sub next { my ($self) = @_; my $rnd = rand( $self->high - $self->low ) + $self->low; return $rnd; } 1; __END__ =pod =encoding utf-8 =head1 NAME Math::Random::OO::Uniform - Generates random numbers from the uniform distribution =head1 VERSION version 0.22 =head1 SYNOPSIS use Math::Random::OO::Uniform; push @prngs, Math::Random::OO::Uniform->new(), # range [0,1) Math::Random::OO::Uniform->new(5), # range [0,5) Math::Random::OO::Uniform->new(-1,1); # range [-1,1) $_->seed(42) for @prngs; print( $_->next() . "\n" ) for @prngs; =head1 DESCRIPTION This subclass of L generates random reals from a uniform probability distribution. =head1 METHODS =head2 C $prng1 = Math::Random::OO::Uniform->new(); $prng2 = Math::Random::OO::Uniform->new($high); $prng3 = Math::Random::OO::Uniform->new($low,$high); C takes up to two optional parameters and returns a new C object. With no parameters, the object generates random numbers in the range of zero (inclusive) to one (exclusive). With a single parameter, the object generates random numbers from zero (inclusive) to the value of the parameter (exclusive). Note, the object does this with multiplication, so if the parameter is negative, the function will return negative numbers. This is a feature or bug, depending on your point of view. With two parameters, the object generates random numbers from the first parameter (inclusive) to the second parameter (exclusive). (Actually, as long as you have two parameters, C will put them in the right order). =head2 C $rv = $prng->seed( @seeds ); This method seeds the random number generator. At the moment, only the first seed value matters. It should be a positive integer. =head2 C $rnd = $prng->next(); This method returns the next random number from the random number generator. It does not take any parameters. =head1 AUTHOR David Golden =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2013 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 =cut Math-Random-OO-0.22/lib/Math/Random/OO/UniformInt.pm000644 000765 000024 00000006643 12155151164 022147 0ustar00davidstaff000000 000000 use 5.006; use strict; use warnings; package Math::Random::OO::UniformInt; # ABSTRACT: Generates random integers with uniform probability our $VERSION = '0.22'; # VERSION # Required modules use Carp; use Params::Validate ':all'; # ISA use base qw( Class::Accessor::Fast ); { my $param_spec = { low => { type => SCALAR }, high => { type => SCALAR } }; __PACKAGE__->mk_accessors( keys %$param_spec ); #__PACKAGE__->mk_ro_accessors( keys %$param_spec ); sub new { my $class = shift; my $self = bless {}, ref($class) ? ref($class) : $class; if ( @_ > 1 ) { my ( $low, $high ) = sort { $a <=> $b } @_[ 0, 1 ]; # DWIM $self->low( int($low) ); $self->high( int($high) ); } elsif ( @_ == 1 ) { $self->low(0); $self->high( int( $_[0] ) ); } else { $self->low(0); $self->high(1); } return $self; } } sub seed { my $self = shift; srand( $_[0] ); } sub next { my ($self) = @_; my $rnd = int( rand( $self->high - $self->low + 1 ) ) + $self->low; return $rnd; } 1; __END__ =pod =encoding utf-8 =head1 NAME Math::Random::OO::UniformInt - Generates random integers with uniform probability =head1 VERSION version 0.22 =head1 SYNOPSIS use Math::Random::OO::UniformInt; push @prngs, Math::Random::OO::UniformInt->new(), # 0 or 1 Math::Random::OO::UniformInt->new(5), # 0, 1, 2, 3, 4, or 5 Math::Random::OO::UniformInt->new(-1,1); # -1, 0, or 1 $_->seed(42) for @prngs; print( $_->next() . "\n" ) for @prngs; =head1 DESCRIPTION This subclass of L generates random integers with uniform probability. =head1 METHODS =head2 C $prng1 = Math::Random::OO::UniformInt->new(); $prng2 = Math::Random::OO::UniformInt->new($high); $prng3 = Math::Random::OO::UniformInt->new($low,$high); C takes up to two optional parameters and returns a new C object. Unlike Uniform, it returns integers inclusive of specified endpoints. With no parameters, the object generates random integers in the range of zero (inclusive) to one (inclusive). With a single parameter, the object generates random numbers from zero (inclusive) to the value of the parameter (inclusive). Note, the object does this with multiplication, so if the parameter is negative, the function will return negative numbers. This is a feature or bug, depending on your point of view. With two parameters, the object generates random integers from the first parameter (inclusive) to the second parameter (inclusive). (Actually, as long as you have two parameters, C will put them in the right order). If parameters are non-integers, they will be truncated to integers before the range is calculated. I.e., C is equivalent to C. =head2 C $rv = $prng->seed( @seeds ); This method seeds the random number generator. At the moment, only the first seed value matters. It should be a positive integer. =head2 C $rnd = $prng->next(); This method returns the next random number from the random number generator. It does not take any parameters. =head1 AUTHOR David Golden =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2013 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 =cut