.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Math::Random::OO 3pm" .TH Math::Random::OO 3pm "2022-12-12" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Math::Random::OO \- Consistent object\-oriented interface for generating random numbers .SH "VERSION" .IX Header "VERSION" version 0.22 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& # 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(), "\en") for (@prngs); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\s-1CPAN\s0 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"\s-1SEE ALSO\*(R"\s0 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. .PP 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. .SH "USAGE" .IX Header "USAGE" .SS "Factory Functions" .IX Subsection "Factory Functions" .Vb 5 \& 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 ); .Ve .PP 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 \&\f(CW\*(C`Math::Random::OO::Subclass\->new()\*(C'\fR each time. The factory function names are the same as the suffix of the subclass following \f(CW\*(C`Math::Random::OO\*(C'\fR. When called, they pass their arguments directly to the \f(CW\*(C`new\*(C'\fR constructor method of the corresponding subclass and return a new object of the subclass type. Supported functions and their subclasses include: .IP "\(bu" 4 \&\f(CW\*(C`Uniform\*(C'\fR \*(-- Math::Random::OO::Uniform (uniform distribution over a range) .IP "\(bu" 4 \&\f(CW\*(C`UniformInt\*(C'\fR \*(-- Math::Random::OO::UniformInt (uniform distribution of integers over a range) .IP "\(bu" 4 \&\f(CW\*(C`Normal\*(C'\fR \*(-- Math::Random::OO::Normal (normal distribution with specified mean and standard deviation) .IP "\(bu" 4 \&\f(CW\*(C`Bootstrap\*(C'\fR \*(-- Math::Random::OO::Bootstrap (bootstrap resampling from a non-parameteric distribution) .SH "INTERFACE" .IX Header "INTERFACE" All Math::Random::OO subclasses must follow a standard interface. They must provide a \f(CW\*(C`new\*(C'\fR method, a \f(CW\*(C`seed\*(C'\fR method, and a \f(CW\*(C`next\*(C'\fR method. Specific details are left to each interface. .ie n .SS """new""" .el .SS "\f(CWnew\fP" .IX Subsection "new" This is the standard constructor. Each subclass will define parameters specific to the subclass. .ie n .SS """seed""" .el .SS "\f(CWseed\fP" .IX Subsection "seed" .Vb 1 \& $prng\->seed( @seeds ); .Ve .PP 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. .PP As seeds may be passed to the built-in \f(CW\*(C`srand()\*(C'\fR function, they may be truncated as integers, so 0.12 and 0.34 would be the same seed. Only positive integers should be used. .ie n .SS """next""" .el .SS "\f(CWnext\fP" .IX Subsection "next" .Vb 1 \& $rnd = $prng\->next(); .Ve .PP This method returns the next random number from the random number generator. It does not take (and must not use) any parameters. .SH "SEE ALSO" .IX Header "SEE ALSO" This is not an exhaustive list \*(-- search \s-1CPAN\s0 for that \*(-- but represents some of the more common or established random number generators that I've come across. .IP "Math::Random \*(-- multiple random number generators for different distributions (a port of the C randlib)" 4 .IX Item "Math::Random multiple random number generators for different distributions (a port of the C randlib)" .PD 0 .IP "Math::Rand48 \*(-- perl bindings for the drand48 library (according to perl56delta, this may already be the default after perl 5.005_52 if available)" 4 .IX Item "Math::Rand48 perl bindings for the drand48 library (according to perl56delta, this may already be the default after perl 5.005_52 if available)" .IP "Math::Random::MT \*(-- The Mersenne Twister \s-1PRNG\s0 (good and fast)" 4 .IX Item "Math::Random::MT The Mersenne Twister PRNG (good and fast)" .IP "Math::TrulyRandom \*(-- an interface to random numbers from interrupt timing discrepancies" 4 .IX Item "Math::TrulyRandom an interface to random numbers from interrupt timing discrepancies" .PD .SH "SUPPORT" .IX Header "SUPPORT" .SS "Bugs / Feature Requests" .IX Subsection "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. .SS "Source Code" .IX Subsection "Source Code" This is open source software. The code repository is available for public review and contribution under the terms of the license. .PP .PP .Vb 1 \& git clone git://github.com/dagolden/math\-random\-oo.git .Ve .SH "AUTHOR" .IX Header "AUTHOR" David Golden .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is Copyright (c) 2013 by David Golden. .PP This is free software, licensed under: .PP .Vb 1 \& The Apache License, Version 2.0, January 2004 .Ve