1classdef DiscreteUniform < DiscreteDistribution
2 % The uniform statistical distribution
4 % Copyright (c) 2012-2026, Imperial College London
8 function self = DiscreteUniform(minVal, maxVal)
9 % SELF = UNIFORM(MINVAL, MAXVAL)
11 % Constructs an uniform distribution with specified minimum and
13 self@DiscreteDistribution(
'DiscreteUniform',2,[minVal,maxVal]);
14 setParam(self, 1,
'min', minVal);
15 setParam(self, 2,
'max', maxVal);
18 function ex = getMean(self)
21 % Get distribution mean
22 ex = (self.getParam(2).paramValue+self.getParam(1).paramValue) / 2;
25 function SCV = getSCV(self)
28 % Get distribution squared coefficient of variation (SCV = variance / mean^2)
29 var = ((self.getParam(2).paramValue-self.getParam(1).paramValue+1)^2-1) / 12;
30 SCV = var/getMean(self)^2;
33 function Ft = evalCDF(self,t)
34 % FT = EVALCDF(SELF,T)
36 % Evaluate the cumulative distribution function at T
38 minVal = self.getParam(1).paramValue;
39 maxVal = self.getParam(2).paramValue;
45 Ft = (floor(t)-minVal+1)/(maxVal-minVal+1);
49 function L = evalLST(self, s)
51 % Evaluate the Laplace-Stieltjes transform of the distribution function at s
52 % For DiscreteUniform(a, b), LST(s) = (e^(-as) - e^(-(b+1)s)) / ((b-a+1)(1 - e^(-s)))
54 a = self.getParam(1).paramValue;
55 b = self.getParam(2).paramValue;
58 % Handle s ≈ 0 case to avoid division by zero
62 numerator = exp(-a * s) - exp(-(b + 1) * s);
63 denominator = (b - a + 1) * (1 - e_neg_s);
64 L = numerator / denominator;
69 function X = sample(self, n)
72 % Get n samples from the distribution
73 if nargin<2 %~exist('n','var'),
76 minVal = self.getParam(1).paramValue;
77 maxVal = self.getParam(2).paramValue;
78 X = round(minVal + (maxVal-minVal)*rand(n,1));
81 function proc = getProcess(self)
84 % Get process representation for non-Markovian distribution
85 % Returns [mean, SCV] pair for use in network analysis
86 proc = [self.getMean(), self.getSCV()];