Math::Random::OO::UniformInt - Generates random integers with uniform


Math-Random-OO documentation  | view source Contained in the Math-Random-OO distribution.

Index


NAME

Top

Math::Random::OO::UniformInt - Generates random integers with uniform probability

SYNOPSIS

Top

  use Math::Random::OO::UniformInt;
  push @prngs,
      Math::Random::OO::UniformInt->new(),     # 0 or 1
      Math::Random::OO::UniformInt->new(5),    # 0, 1, 2, 3, 4, or 5
      Math::Random::OO::UniformInt->new(-1,1); # -1, 0, or 1
  $_->seed(42) for @prngs;
  print( $_->next() . "\n" ) for @prngs;

DESCRIPTION

Top

This subclass of Math::Random::OO generates random integers with uniform probability.

USAGE

Top

new

 $prng1 = Math::Random::OO::UniformInt->new();
 $prng2 = Math::Random::OO::UniformInt->new($high);
 $prng3 = Math::Random::OO::UniformInt->new($low,$high);

new takes up to two optional parameters and returns a new Math::Random::OO::UniformInt object. Unlike Uniform, it returns integers inclusive of specified endpoints. With no parameters, the object generates random integers in the range of zero (inclusive) to one (inclusive). With a single parameter, the object generates random numbers from zero (inclusive) to the value of the parameter (inclusive). Note, the object does this with multiplication, so if the parameter is negative, the function will return negative numbers. This is a feature or bug, depending on your point of view. With two parameters, the object generates random integers from the first parameter (inclusive) to the second parameter (inclusive). (Actually, as long as you have two parameters, new will put them in the right order). If parameters are non-integers, they will be truncated to integers before the range is calculated. I.e., new(-1.2, 3.6) is equivalent to new(-1,3).

seed

 $rv = $prng->seed( @seeds );

This method seeds the random number generator. At the moment, only the first seed value matters.

next

 $rnd = $prng->next();

This method returns the next random number from the random number generator. It does not take any parameters.

BUGS

Top

Please report bugs using the CPAN Request Tracker at

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Math-Random-OO

AUTHOR

Top

David A. Golden (DAGOLDEN)

dagolden@dagolden.com

http://dagolden.com/

COPYRIGHT

Top

SEE ALSO

Top

Math::Random::OO


Math-Random-OO documentation  | view source Contained in the Math-Random-OO distribution.