MT(3pm)
π MT β Math::Random::MT π
okay bestie, so this is the manual page for Math::Random::MT β aka the Mersenne Twister PRNG, living its best life in the User Contributed Perl Documentation section of your man pages. pull up a chair, we're gonna get you fluent in random numbers π
β¨ NAME β¨
Math::Random::MT β the Mersenne Twister PRNG. no cap, that's the whole vibe. π
πΈ SYNOPSIS πΈ
two whole interfaces, pick your fighter:
## 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
likeβ¦ look at that. she does it all π«Ά
π¦ DESCRIPTION π¦
so the Mersenne Twister is a pseudorandom number generator, and it was developed by Makoto Matsumoto and Takuji Nishimura. it's described in their paper at <URL:http://www.math.keio.ac.jp/~nisimura/random/doc/mt.ps>. this algorithm has a very uniform distribution and it's genuinely great for modelling purposes β but listen to me, bestie, do not use it for cryptography. i said what i said. π₯
this module implements two interfaces:
π Object-oriented interface
new()β creates a new generator that is automatically seeded based ongettimeofday. cute, effortless, self-seeding β¨new($seed)β creates a new generator seeded with an unsigned 32-bit integer.new(@seeds)β creates a new generator seeded with an array of (up to 624) unsigned 32-bit integers. yes, 624. iconic number, don't question it.set_seed()β seeds the generator and returns the seed used. it takes the same arguments asnew(). very "give me something, i'll give it right back" of it πget_seed()β retrieves the value of the seed used. so you can peek. we love an honest queen πrand($num)β behaves exactly like Perl's builtinrand(), returning a number uniformly distributed in[0, $num)($numdefaults to1).irand()β returns a 32-bit integer, i.e. an integer uniformly distributed in[0, 2^32-1].
π Function-oriented interface
srand($seed)β behaves just like Perl's builtinsrand(). as in Perl >= 5.14, the seed is returned. and if you use this interface, it is strongly recommended that you callsrand()explicitly, rather than relying onrand()to call it the first time it is used. do it on purpose, bestie, don't makerand()do the emotional labour for you πrand($num)β behaves exactly like Perl's builtinrand(), returning a number uniformly distributed in[0, $num)($numdefaults to1).irand()β returns a 32-bit integer, i.e. an integer uniformly distributed in[0, 2^32-1].
π SEE ALSO π
<URL:http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html>Data::Entropy
go read them, they're giving supporting-docs energy π
π«Ά ACKNOWLEDGEMENTS π«Ά
- Sean M. Burke β for giving me the idea to write this module.
- Philip Newton β for several useful patches.
- Florent Angly β for implementing seed generation and retrieval.
the founding mothers and fathers of this module, fr fr πΈ
π AUTHOR π
Abhijit Menon-Sen <ams@toroid.org>
Copyright 2001 Abhijit Menon-Sen. All rights reserved.
Based on the C implementation of MT19937 Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura
This software is distributed under a (three-clause) BSD-style license. See the LICENSE file in the distribution for details.
π real talk: it's a (three-clause) BSD-style license, so go read the actual LICENSE file in the distribution for the details. i'm just the messenger π§
and that's the whole page, bestie! this was perl v5.42.3, dated 2026-08-19, and it's the MT(3pm) man page from User Contributed Perl Documentation. go forth and be random πβ¨π
π¦ where this page comes from
- ubuntu stonking: libmath-random-mt-perl 1.17-2build6 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms