.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (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 .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . 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 "MT 3pm" .TH MT 3pm 2024-03-07 "perl v5.38.2" "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 \fBnew()\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 \fBset_seed()\fR 4 .IX Item "set_seed()" Seeds the generator and returns the seed used. It takes the same arguments as \&\fR\f(BInew()\fR\fI\fR. .IP \fBget_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 \fBrand()\fR, returning a number uniformly distributed in [0, \f(CW$num\fR) ($num defaults to 1). .IP \fBirand()\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 \fBsrand()\fR. As in Perl >= 5.14, the seed is returned. If you use this interface, it is strongly recommended that you call \fR\f(BIsrand()\fR\fI\fR explicitly, rather than relying on \fI\fR\f(BIrand()\fR\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 \fBrand()\fR, returning a number uniformly distributed in [0, \f(CW$num\fR) ($num defaults to 1). .IP \fBirand()\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 MT19937 Copyright (C) 1997 \- 2002, Makoto Matsumoto and Takuji Nishimura .PP This software is distributed under a (three-clause) BSD-style license. See the LICENSE file in the distribution for details.