<?php
namespace PHPStats\PDistribution;



use PHPStats\Exception as PHPStatsException,
    PHPStats\PCalculator\DiscreteUniform as DiscreteUniformCalculator;

/**
* DiscreteUniform class
* 
* Represents the discrete uniform distribution, which is a range of equiprobable
* outcomes, such as rolling a single die.
*
* For more information, see: http://en.wikipedia.org/wiki/Uniform_distribution_%28discrete%29
*
* @author Michael Cordingley <Michael.Cordingley@gmail.com>
*/
class DiscreteUniform implements ProbabilityDistributionInterface
{
    private $minimum;
    private $maximum;
    
    /**
      *  @var DiscreteUniformCalculator 
      */
    protected $calculator;
    
    /**
     * Constructor 
     *
     * @param int $minimum The minimum value the distribution can take on
     * @param int $maximum The maximum value the distribution can take on
     * @param DiscreteUniformCalculator $cal instance of a calculator
     */
    public function __construct($minimum = 0, $maximum = 1, DiscreteUniformCalculator $cal)
    {
	$this->minimum    = $minimum;
	$this->maximum    = $maximum;
	$this->calculator = $cal;
    }
    
    /**
     * Returns a random float between $minimum and $minimum plus $maximum
     * 
     * @return float The random variate.
     */
    public function rvs()
    {
	return $this->calculator->getRvs($this->minimum, $this->maximum);
    }
    
    /**
     * Returns the probability mass function
     * 
     * @param float $x The test value
     * @return float The probability
     */
    public function pmf($x)
    {
	return $this->calculator->getPmf($x, $this->minimum, $this->maximum);
    }
    
    /**
     * Probability Distribution function
     * 
     * Alias for pmf
     * 
     * @param float $x The test value
     * @return float The probability
     */
    public function pdf($x)
    {
	return $this->calculator->pmf($x);
    }
    
    /**
     * Returns the cumulative distribution function, the probability of getting the test value or something below it
     * 
     * @param float $x The test value
     * @return float The probability
     */
    public function cdf($x)
    {
	return $this->calculator->getCdf($x, $this->minimum, $this->maximum);
    }
    
    /**
     * Returns the survival function, the probability of getting the test value or something above it
     * 
     * @param float $x The test value
     * @return float The probability
     */
    public function sf($x)
    {
	return $this->calculator->getSf($x, $this->minimum, $this->maximum);
    }
    
    /**
     * Returns the percent-point function, the inverse of the cdf
     * 
     * @param float $x The test value
     * @return float The value that gives a cdf of $x
     */
    public function ppf($x)
    {
	return $this->calculator->getPpf($x, $this->minimum, $this->maximum);
    }
    
    /**
     * Returns the inverse survival function, the inverse of the sf
     * 
     * @param float $x The test value
     * @return float The value that gives an sf of $x
     */
    public function isf($x)
    {
	return $this->calculator->getIsf($x, $this->minimum, $this->maximum);
    }
    
    /**
     * Returns the moments of the distribution
     * 
     * @param string $moments Which moments to compute. m for mean, v for variance, s for skew, k for kurtosis.  Default 'mv'
     * @return type array A dictionary containing the first four moments of the distribution
     */
    public function stats($moments = 'mv')
    {
	return $this->calculator->getStats($moments, $this->minimum, $this->maximum);
    }
    
}
/* End of File */