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
P = evalPMF(self,k)
52 % Evaluate
the probability mass function at K
54 minVal = self.getParam(1).paramValue;
55 maxVal = self.getParam(2).paramValue;
56 if k < minVal || k > maxVal
59 P = 1/(maxVal-minVal+1);
63 function L = evalLST(self, s)
65 % Evaluate
the Laplace-Stieltjes transform of
the distribution function at s
66 % For DiscreteUniform(a, b), LST(s) = (e^(-as) - e^(-(b+1)s)) / ((b-a+1)(1 - e^(-s)))
68 a = self.getParam(1).paramValue;
69 b = self.getParam(2).paramValue;
72 % Handle s ≈ 0 case to avoid division by zero
76 numerator = exp(-a * s) - exp(-(b + 1) * s);
77 denominator = (b - a + 1) * (1 - e_neg_s);
78 L = numerator / denominator;
83 function X = sample(self, n)
86 % Get n samples from
the distribution
87 if nargin<2 %~exist('n','var'),
90 minVal = self.getParam(1).paramValue;
91 maxVal = self.getParam(2).paramValue;
92 X = round(minVal + (maxVal-minVal)*rand(n,1));
95 function proc = getProcess(self)
98 % Get process representation for non-Markovian distribution
99 % Returns [mean, SCV] pair for use in network analysis
100 proc = [self.getMean(), self.getSCV()];