Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

math::random::mt(3pm) [debian man page]

MT(3pm) 						User Contributed Perl Documentation						   MT(3pm)

NAME
Math::Random::MT - The Mersenne Twister PRNG SYNOPSIS
## 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 DESCRIPTION
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: Object-oriented interface 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. 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]. Function-oriented interface 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]. SEE ALSO
<URL:http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html> Data::Entropy 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. 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. perl v5.14.2 2012-08-07 MT(3pm)

Check Out this Related Man Page

RAND(3) 						     Linux Programmer's Manual							   RAND(3)

NAME
rand, srand - random number generator. SYNOPSIS
#include <stdlib.h> int rand(void); void srand(unsigned int seed); DESCRIPTION
The rand() function returns a pseudo-random integer between 0 and RAND_MAX. The srand() function sets its argument as the seed for a new sequence of pseudo-random integers to be returned by rand(). These sequences are repeatable by calling srand() with the same seed value. If no seed value is provided, the rand() function is automatically seeded with a value of 1. RETURN VALUE
The rand() function returns a value between 0 and RAND_MAX. The srand() returns no value. NOTES
The versions of rand() and srand() in the Linux C Library use the same random number generator as random() and srandom(), so the lower- order bits should be as random as the higher-order bits. However, on older rand() implementations, the lower-order bits are much less ran- dom than the higher-order bits. In Numerical Recipes in C: The Art of Scientific Computing (William H. Press, Brian P. Flannery, Saul A. Teukolsky, William T. Vetterling; New York: Cambridge University Press, 1992 (2nd ed., p. 277)), the following comments are made: "If you want to generate a random integer between 1 and 10, you should always do it by using high-order bits, as in j=1+(int) (10.0*rand()/(RAND_MAX+1.0)); and never by anything resembling j=1+(rand() % 10); (which uses lower-order bits)." Random-number generation is a complex topic. The Numerical Recipes in C book (see reference above) provides an excellent discussion of practical random-number generation issues in Chapter 7 (Random Numbers). For a more theoretical discussion which also covers many practical issues in depth, please see Chapter 3 (Random Numbers) in Donald E. Knuth's The Art of Computer Programming, volume 2 (Seminumerical Algorithms), 2nd ed.; Reading, Massachusetts: Addison-Wesley Publishing Company, 1981. CONFORMING TO
SVID 3, BSD 4.3, ISO 9899 SEE ALSO
random(3), srandom(3), initstate(3), setstate(3) GNU
1995-05-18 RAND(3)
Man Page