Perl.pm

- NAME
- SYNOPSIS
- DESCRIPTION

- Functions
- Export

- SPEED
- SEE ALSO
- AUTHOR
- COPYRIGHT AND LICENSE

# NAME

Math::Random::MT::Perl - Pure Perl Pseudorandom Number Generator

# SYNOPSIS

     use Math::Random::MT::Perl;

     $gen = Math::Random::MT::Perl->new($seed);
     print $gen->rand(3);

     OR

     use Math::Random::MT qw(srand rand);

     # now srand and rand behave as usual, except with 32 bit precsision not ~15

# DESCRIPTION

Pure Perl implementation of the Mersenne Twister algorithm as implemented in C/XS in Math::Random::MT. The output is identical to the C/XS version. The Mersenne Twister is a 32 bit pseudorandom number generator developed by Makoto Matsumoto and Takuji Nishimura.

This module implements the same two interfaces found in Math::Random::MT, as described in the synopsis above. It defines the following functions.

## Functions

`new($seed)`

  Creates a new generator seeded with an unsigned 32-bit integer.

`new(@seed)`

  Creates a new generator seeded with an array of unsigned 32-bit integers.

`rand($num)`

  Can be called via the OO in interface or exported. Behaves exactly like Perl's builtin `rand()`, returning a number uniformly distributed in [0, $num) ($num defaults to 1) except the underlying complexity is 32 bits rather than some small fraction of this.

`srand($seed)`

  Behaves just like Perl's builtin `srand()`. If you use this interface, it is strongly recommended that you call srand() explicitly, rather than relying on rand() to call it the first time it is used. Has no effect if called via OO interface - pass the seed(s) to new.

## Export

Nothing by default. `rand()` and `srand()` on demand.

# SPEED

Runs around 1/3-1/2 as fast as Math::Random::MT, however that still means a Benchmark random number generation speed of 100,000/sec on modest hardware, so this is unlikely to cause a significant bottleneck in most circumstances.

# SEE ALSO

Math::Random::MT

http://www.math.keio.ac.jp/~matumoto/emt.html

# AUTHOR

Dr James Freeman <airmedical@gmail.com>

# COPYRIGHT AND LICENSE

Copyright (C) 2008 by Dr James Freeman

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

Perl.pm