Math-Random-Free-0.2.0/0000775000175000017500000000000014051375171014401 5ustar andriusandriusMath-Random-Free-0.2.0/README0000644000175000017500000000050214051375171015254 0ustar andriusandrius This archive contains the distribution Math-Random-Free, version 0.2.0: Free drop-in replacement for Math::Random This software is Copyright (c) 2021 by Andrius Merkys. This is free software, licensed under: The (three-clause) BSD License This README file was generated by Dist::Zilla::Plugin::Readme v6.010. Math-Random-Free-0.2.0/Makefile.PL0000644000175000017500000000203614051375171016352 0ustar andriusandrius# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.010. use strict; use warnings; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Free drop-in replacement for Math::Random", "AUTHOR" => "Andrius Merkys ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Math-Random-Free", "LICENSE" => "bsd", "NAME" => "Math::Random::Free", "PREREQ_PM" => { "Digest::SHA" => 0, "List::Util" => 0 }, "TEST_REQUIRES" => { "Test::More" => 0 }, "VERSION" => "0.2.0", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Digest::SHA" => 0, "List::Util" => 0, "Test::More" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); Math-Random-Free-0.2.0/lib/0000775000175000017500000000000014051375171015147 5ustar andriusandriusMath-Random-Free-0.2.0/lib/Math/0000775000175000017500000000000014051375171016040 5ustar andriusandriusMath-Random-Free-0.2.0/lib/Math/Random/0000775000175000017500000000000014051375171017260 5ustar andriusandriusMath-Random-Free-0.2.0/lib/Math/Random/Free.pm0000644000175000017500000001036014051375171020475 0ustar andriusandriuspackage Math::Random::Free; use strict; use warnings; # ABSTRACT: Free drop-in replacement for Math::Random our $VERSION = '0.2.0'; # VERSION =pod =head1 NAME Math::Random::Free - free drop-in replacement for Math::Random =head1 DESCRIPTION This is free (see below) implementation of L 0.72, serving as drop-in replacement for this module. =head1 MOTIVATION L is a great and widely-used module for the generation of random numbers and permutations. Despite being open-source, L does not fulfill free open-source software definitions as established by the Open Source Initiative (L) and the Debian Project (L, a.k.a. DFSG). This is mostly because C code cannot be copied nor distributed for direct commercial advantage. Math::Random::Free is created to free the code depending on L from these limitations. =cut use Digest::SHA qw( sha1_hex ); use List::Util qw( shuffle ); require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw( random_normal random_permutation random_permuted_index random_set_seed_from_phrase ); our @EXPORT_OK = qw( random_exponential random_normal random_permutation random_permuted_index random_set_seed_from_phrase random_uniform random_uniform_integer ); our $PI = 4 * atan2( 1, 1 ); =head1 SUPPORT our @EXPORT = qw( random_normal random_permutation random_permuted_index random_set_seed_from_phrase ); our @EXPORT_OK = qw( random_exponential random_normal random_permutation random_permuted_index random_set_seed_from_phrase random_uniform random_uniform_integer ); =cut sub random_exponential { my( $n, $rate ) = @_; $n = 1 unless defined $n; $rate = 1 unless defined $rate; if( wantarray ) { return map { scalar random_exponential( $n, $rate ) } 1..$n; } else { return log( 1 - rand ) / -$rate; } } sub random_normal { my( $n, $mean, $sd ) = @_; $n = 1 unless defined $n; $mean = 0 unless defined $mean; $sd = 1 unless defined $sd; if( wantarray ) { return map { scalar random_normal( $n, $mean, $sd ) } 1..$n; } else { # Box-Muller method return $mean + $sd * cos( 2 * $PI * (1 - rand) ) * sqrt( -2 * log(1 - rand) ); } } sub random_permutation { my( @array ) = @_; return @array[random_permuted_index( scalar @array )]; } sub random_permuted_index { my( $n ) = @_; return shuffle 0..$n-1; } sub random_set_seed_from_phrase { my( $seed ) = @_; # On 64-bit machine the max. value for srand() seems to be 2**50-1 srand hex substr( sha1_hex( $seed ), 0, 6 ); } sub random_uniform { my( $n, $low, $high ) = @_; $n = 1 unless defined $n; $low = 0 unless defined $low; $high = 1 unless defined $high; if( wantarray ) { return map { rand() * ($high - $low) + $low } 1..$n; } else { return rand() * ($high - $low) + $low; } } sub random_uniform_integer { my( $n, $low, $high ) = @_; my $range = int($high) - int($low) + 1; if( wantarray ) { return map { int( rand($range) + $low ) } 1..$n; } else { return int( rand($range) + $low ); } } =head1 CAVEATS This module has only a subset of L subroutines (contributions welcome), implemented using either Perl core subroutines or other well-known modules. Thus Math::Random::Free is neither as complete, nor as fast, nor as random as L. Also Math::Random::Free does not aim for cryptographic security. While Math::Random::Free supports seed setting, it does that differently from L. It means that one should not expect the same seed producing identical random sequences in both modules. As Math::Random::Free employs L for producing random permutations, these are influenced by C<$List::Util::RAND> variable. =head1 TESTED WITH =over 4 =item * L 0.02 =back =head1 AUTHOR Andrius Merkys, L =cut 1; Math-Random-Free-0.2.0/META.json0000644000175000017500000000235214051375171016022 0ustar andriusandrius{ "abstract" : "Free drop-in replacement for Math::Random", "author" : [ "Andrius Merkys " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.010, CPAN::Meta::Converter version 2.150010", "license" : [ "bsd" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Math-Random-Free", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Digest::SHA" : "0", "List::Util" : "0" } }, "test" : { "requires" : { "Test::More" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/merkys/math-random-free/issues" }, "homepage" : "https://search.cpan.org/dist/Math-Random-Free", "repository" : { "type" : "git", "url" : "git://github.com/merkys/math-random-free.git", "web" : "https://github.com/merkys/math-random-free" } }, "version" : "0.2.0", "x_serialization_backend" : "JSON::XS version 3.04" } Math-Random-Free-0.2.0/dist.ini0000644000175000017500000000071014051375171016041 0ustar andriusandriusname = Math-Random-Free author = Andrius Merkys license = BSD copyright_holder = Andrius Merkys copyright_year = 2021 version = 0.2.0 [@Filter] -bundle = @Basic -remove = License [AutoMetaResources] homepage = https://search.cpan.org/dist/%{dist} repository.github = user:merkys bugtracker.github = user:merkys [MetaJSON] [OurPkgVersion] [Prereqs] Digest::SHA = 0 List::Util = 0 [Prereqs / Test] -phase = test Test::More = 0 Math-Random-Free-0.2.0/Changes0000644000175000017500000000017114051375171015671 0ustar andriusandrius0.2.0 2021-05-20 - Implementing random_exponential() and random_normal(). 0.1.0 2021-05-11 - Initial release. Math-Random-Free-0.2.0/META.yml0000644000175000017500000000131614051375171015651 0ustar andriusandrius--- abstract: 'Free drop-in replacement for Math::Random' author: - 'Andrius Merkys ' build_requires: Test::More: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.010, CPAN::Meta::Converter version 2.150010' license: bsd meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Math-Random-Free requires: Digest::SHA: '0' List::Util: '0' resources: bugtracker: https://github.com/merkys/math-random-free/issues homepage: https://search.cpan.org/dist/Math-Random-Free repository: git://github.com/merkys/math-random-free.git version: 0.2.0 x_serialization_backend: 'YAML::Tiny version 1.70' Math-Random-Free-0.2.0/LICENSE0000644000175000017500000000273314051375171015411 0ustar andriusandriusCopyright (c) The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Math-Random-Free-0.2.0/t/0000775000175000017500000000000014051375171014644 5ustar andriusandriusMath-Random-Free-0.2.0/t/01_basic.t0000644000175000017500000000136214051375171016412 0ustar andriusandrius#!/usr/bin/perl use strict; use warnings; use Math::Random::Free qw( random_exponential random_normal random_permutation random_set_seed_from_phrase random_uniform_integer ); use Test::More; my @tested = ( sub { return random_uniform_integer( 1, 1, 123 ) }, sub { return join ',', random_permutation( 0..9 ) }, sub { return join ',', random_normal( 5 ) }, sub { return random_exponential }, ); plan tests => scalar @tested; sub seed_and_test { my( $function ) = @_; random_set_seed_from_phrase( 'Math::Random::Free' ); return $function->(); } for (@tested) { is( seed_and_test( $_ ), seed_and_test( $_ ) ); } Math-Random-Free-0.2.0/MANIFEST0000644000175000017500000000027614051375171015535 0ustar andriusandrius# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.010. Changes LICENSE MANIFEST META.json META.yml Makefile.PL README dist.ini lib/Math/Random/Free.pm t/01_basic.t