1. Perl
  2. Module
  3. here

Math::Random::MT - Generates pseudo - random numbers close to natural random numbers

A good algorithm for generating pseudo-random numbers is the Mersenne Twister method .

The module that finds pseudo-random numbers by the Mersenne Twister method is Math::Random::MT . You can get it from CAPN.

use Math::Random::MT qw/rand srand/;

srand time ^ $$;
my $num = rand 100

Used in the same way as the standard Perl modules rand function and srand function can. When using Math::Randam::MT, make sure to call the srand function explicitly.

time function is the time, and $$is process ID, which is the initial value given to srand. I try to make the values as random as possible.


This is an example using Math::Randam::MT.

use strict;
use warnings;

use Math::Random::MT qw/rand srand/;

print "(1) Generates a random random number.\n";
# Give as random an initial value as possible.
srand time ^ $$;
for my $i (1 .. 20) {
  print "$i times:". Int (rand 100) . "\n";
print "\n";

Related Informatrion