| 1 |
NAME |
| 2 |
Math::Random::MT - The Mersenne Twister PRNG |
| 3 |
|
| 4 |
SYNOPSIS |
| 5 |
## Object-oriented interface: |
| 6 |
use Math::Random::MT; |
| 7 |
$gen = Math::Random::MT->new() # or... |
| 8 |
$gen = Math::Random::MT->new($seed); # or... |
| 9 |
$gen = Math::Random::MT->new(@seeds); |
| 10 |
$seed = $gen->get_seed(); # seed used to generate the random numbers |
| 11 |
$rand = $gen->rand(42); # random number in the interval [0, 42) |
| 12 |
$dice = int($gen->rand(6)+1); # random integer between 1 and 6 |
| 13 |
$coin = $gen->rand() < 0.5 ? # flip a coin |
| 14 |
"heads" : "tails" |
| 15 |
$int = $gen->irand(); # random integer in [0, 2^32-1] |
| 16 |
|
| 17 |
## Function-oriented interface: |
| 18 |
use Math::Random::MT qw(srand rand irand); |
| 19 |
# now use srand() and rand() as you usually do in Perl |
| 20 |
|
| 21 |
DESCRIPTION |
| 22 |
The Mersenne Twister is a pseudorandom number generator developed by |
| 23 |
Makoto Matsumoto and Takuji Nishimura. It is described in their paper at |
| 24 |
<URL:http://www.math.keio.ac.jp/~nisimura/random/doc/mt.ps>. This |
| 25 |
algorithm has a very uniform distribution and is good for modelling |
| 26 |
purposes but do not use it for cryptography. |
| 27 |
|
| 28 |
This module implements two interfaces: |
| 29 |
|
| 30 |
Object-oriented interface |
| 31 |
new() |
| 32 |
Creates a new generator that is automatically seeded based on |
| 33 |
gettimeofday. |
| 34 |
|
| 35 |
new($seed) |
| 36 |
Creates a new generator seeded with an unsigned 32-bit integer. |
| 37 |
|
| 38 |
new(@seeds) |
| 39 |
Creates a new generator seeded with an array of (up to 624) unsigned |
| 40 |
32-bit integers. |
| 41 |
|
| 42 |
set_seed() |
| 43 |
Seeds the generator. It takes the same arguments as *new()*. |
| 44 |
|
| 45 |
get_seed() |
| 46 |
Retrieves the value of the seed used. |
| 47 |
|
| 48 |
rand($num) |
| 49 |
Behaves exactly like Perl's builtin rand(), returning a number |
| 50 |
uniformly distributed in [0, $num) ($num defaults to 1). |
| 51 |
|
| 52 |
irand() |
| 53 |
Returns a 32-bit integer, i.e. an integer uniformly distributed in |
| 54 |
[0, 2^32-1]. |
| 55 |
|
| 56 |
Function-oriented interface |
| 57 |
srand($seed) |
| 58 |
Behaves just like Perl's builtin srand(). As in Perl >= 5.14, the |
| 59 |
seed is returned. If you use this interface, it is strongly |
| 60 |
recommended that you call *srand()* explicitly, rather than relying |
| 61 |
on *rand()* to call it the first time it is used. |
| 62 |
|
| 63 |
rand($num) |
| 64 |
Behaves exactly like Perl's builtin rand(), returning a number |
| 65 |
uniformly distributed in [0, $num) ($num defaults to 1). |
| 66 |
|
| 67 |
irand() |
| 68 |
Returns a 32-bit integer, i.e. an integer uniformly distributed in |
| 69 |
[0, 2^32-1]. |
| 70 |
|
| 71 |
SEE ALSO |
| 72 |
<URL:http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html> |
| 73 |
|
| 74 |
Data::Entropy |
| 75 |
|
| 76 |
ACKNOWLEDGEMENTS |
| 77 |
Sean M. Burke |
| 78 |
For giving me the idea to write this module. |
| 79 |
|
| 80 |
Philip Newton |
| 81 |
For several useful patches. |
| 82 |
|
| 83 |
Florent Angly |
| 84 |
For implementing seed generation and retrieval. |
| 85 |
|
| 86 |
AUTHOR |
| 87 |
Abhijit Menon-Sen <[email protected]> |
| 88 |
|
| 89 |
Copyright 2001 Abhijit Menon-Sen. All rights reserved. |
| 90 |
|
| 91 |
Based on the C implementation of MT19937 Copyright (C) 1997 - 2002, |
| 92 |
Makoto Matsumoto and Takuji Nishimura |
| 93 |
|
| 94 |
This software is distributed under a (three-clause) BSD-style license. |
| 95 |
See the LICENSE file in the distribution for details. |
| 96 |
|