GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
MT(3) User Contributed Perl Documentation MT(3)

Math::Random::MT - The Mersenne Twister PRNG

  ## 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

The Mersenne Twister is a pseudorandom number generator developed by Makoto Matsumoto and Takuji Nishimura. It is 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 is good for modelling purposes but do not use it for cryptography.

This module implements two interfaces:

new()
Creates a new generator that is automatically seeded based on gettimeofday.
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.
set_seed()
Seeds the generator and returns the seed used. It takes the same arguments as new().
get_seed()
Retrieves the value of the seed used.
rand($num)
Behaves exactly like Perl's builtin rand(), returning a number uniformly distributed in [0, $num) ($num defaults to 1).
irand()
Returns a 32-bit integer, i.e. an integer uniformly distributed in [0, 2^32-1].

srand($seed)
Behaves just like Perl's builtin srand(). As in Perl >= 5.14, the seed is returned. 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.
rand($num)
Behaves exactly like Perl's builtin rand(), returning a number uniformly distributed in [0, $num) ($num defaults to 1).
irand()
Returns a 32-bit integer, i.e. an integer uniformly distributed in [0, 2^32-1].

<URL:http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html>

Data::Entropy

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.

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.

2015-11-27 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.