.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" 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 .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "MT 3pm" .TH MT 3pm "2015-12-01" "perl v5.24.1" "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::MT \- The Mersenne Twister PRNG .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 11 \& ## Object\-oriented interface: \& use Math::Random::MT; \& $gen = Math::Random::MT\->new() # or... \& $gen = Math::Random::MT\->new($seed); # or... \& $gen = Math::Random::MT\->new(@seeds); \& $seed = $gen\->get_seed(); # seed used to generate the random numbers \& $rand = $gen\->rand(42); # random number in the interval [0, 42) \& $dice = int($gen\->rand(6)+1); # random integer between 1 and 6 \& $coin = $gen\->rand() < 0.5 ? # flip a coin \& "heads" : "tails" \& $int = $gen\->irand(); # random integer in [0, 2^32\-1] \& \& ## Function\-oriented interface: \& use Math::Random::MT qw(srand rand irand); \& # now use srand() and rand() as you usually do in Perl .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The Mersenne Twister is a pseudorandom number generator developed by Makoto Matsumoto and Takuji Nishimura. It is described in their paper at . This algorithm has a very uniform distribution and is good for modelling purposes but do not use it for cryptography. .PP This module implements two interfaces: .SS "Object-oriented interface" .IX Subsection "Object-oriented interface" .IP "\fInew()\fR" 4 .IX Item "new()" Creates a new generator that is automatically seeded based on gettimeofday. .IP "new($seed)" 4 .IX Item "new($seed)" Creates a new generator seeded with an unsigned 32\-bit integer. .IP "new(@seeds)" 4 .IX Item "new(@seeds)" Creates a new generator seeded with an array of (up to 624) unsigned 32\-bit integers. .IP "\fIset_seed()\fR" 4 .IX Item "set_seed()" Seeds the generator and returns the seed used. It takes the same arguments as \&\fI\fInew()\fI\fR. .IP "\fIget_seed()\fR" 4 .IX Item "get_seed()" Retrieves the value of the seed used. .IP "rand($num)" 4 .IX Item "rand($num)" Behaves exactly like Perl's builtin \fIrand()\fR, returning a number uniformly distributed in [0, \f(CW$num\fR) ($num defaults to 1). .IP "\fIirand()\fR" 4 .IX Item "irand()" Returns a 32\-bit integer, i.e. an integer uniformly distributed in [0, 2^32\-1]. .SS "Function-oriented interface" .IX Subsection "Function-oriented interface" .IP "srand($seed)" 4 .IX Item "srand($seed)" Behaves just like Perl's builtin \fIsrand()\fR. As in Perl >= 5.14, the seed is returned. If you use this interface, it is strongly recommended that you call \fI\fIsrand()\fI\fR explicitly, rather than relying on \fI\fIrand()\fI\fR to call it the first time it is used. .IP "rand($num)" 4 .IX Item "rand($num)" Behaves exactly like Perl's builtin \fIrand()\fR, returning a number uniformly distributed in [0, \f(CW$num\fR) ($num defaults to 1). .IP "\fIirand()\fR" 4 .IX Item "irand()" Returns a 32\-bit integer, i.e. an integer uniformly distributed in [0, 2^32\-1]. .SH "SEE ALSO" .IX Header "SEE ALSO" .PP Data::Entropy .SH "ACKNOWLEDGEMENTS" .IX Header "ACKNOWLEDGEMENTS" .IP "Sean M. Burke" 4 .IX Item "Sean M. Burke" For giving me the idea to write this module. .IP "Philip Newton" 4 .IX Item "Philip Newton" For several useful patches. .IP "Florent Angly" 4 .IX Item "Florent Angly" For implementing seed generation and retrieval. .SH "AUTHOR" .IX Header "AUTHOR" Abhijit Menon-Sen .PP Copyright 2001 Abhijit Menon-Sen. All rights reserved. .PP Based on the C implementation of \s-1MT19937\s0 Copyright (C) 1997 \- 2002, Makoto Matsumoto and Takuji Nishimura .PP This software is distributed under a (three-clause) BSD-style license. See the \s-1LICENSE\s0 file in the distribution for details.