As far as I know, Mathematica lacks a definition for a probability distribution representing a constant random variable.

Is this assertion correct?

Is there a problem in making such a distribution well-defined in Mathematica (assuming we treat it as a continuous rather than a discrete distribution)?

In principle, we could add definitions for this distribution, e.g.

CDF[ConstantDistribution[μ_]] ^:= UnitStep[# - μ] &

How would I find what definitions are needed to make it a "first class" member of the set of distributions supported by Mathematica? So that, for example, it could be used in functions such as TransformedDistribution?

In general, there are ways to work around the lack of such a distribution, but just as it is sometimes useful to have a function such as Identity (e.g. to pass to a function that transforms an input) it can be useful to have the "trivial" distribution.

  • $\begingroup$ Is this too limited: constantD = UniformDistribution[{4.3, 4.3}]; RandomVariate[constantD, 10] ? This results in {4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3}. But the PDF and CDF functions don't work with this. $\endgroup$
    – JimB
    Commented May 15, 2019 at 21:51
  • $\begingroup$ @JimB I think defining it in terms of pre-defined distributions would be a simple way forward. But as you show, your example doesn't work fully and neither does setting the SD = 0 in a Normal distribution. $\endgroup$
    – mikado
    Commented May 15, 2019 at 21:58

4 Answers 4


A relatively simple trick can achieve this

ConstantDistribution[m_] = TransformedDistribution[m, {x \[Distributed] NormalDistribution[0, 1]}];

This behaves as desired for some key functions

{Mean, Variance, CDF[#, t] &, CharacteristicFunction[#, t] &}[ConstantDistribution[m]] // Through // InputForm
(* {m, 0, Piecewise[{{1, m - t <= 0}}, 0], E^(I*m*t)} *)
  • 1
    $\begingroup$ Wow! Even Expectation works with this approach. $\endgroup$
    – JimB
    Commented May 17, 2019 at 18:12

In[35]:= dist = ProbabilityDistribution[1, {x, a, a, 1}];

In[36]:= DistributionParameterQ[dist]

Out[36]= True

In[39]:= {Mean[dist], Variance[dist], CDF[dist, x], Expectation[s^2 + 1, s [Distributed] dist]} // InputForm

Out[39]//InputForm= {a, 0, Piecewise[{{1, a <= x}}, 0], 1 + a^2}

  • $\begingroup$ Interesting - technically you have defined a discrete distribution that only takes the value a, whereas my answer defined a continuous distribution. Mathematica makes a distinction between the two types, at least in PDF $\endgroup$
    – mikado
    Commented Jun 18, 2019 at 21:03
  • $\begingroup$ The integral of a finite function from a to a is zero... This really should not work, but I guess the framework is just too robust ;) In[62]:= td = TransformedDistribution[3, {x [Distributed] NormalDistribution[0, 1]}]; In[63]:= DistributionDomain[td] Out[63]= Interval[{3, 3}] In[64]:= DistributionParameterQ[td] Out[64]= True In[69]:= PDF[td, x] // InputForm Out[69]//InputForm= Piecewise[{{0, x != 3}}, Indeterminate] $\endgroup$
    – Gosia
    Commented Jun 18, 2019 at 21:14
EmpiricalDistribution[{1} -> {m}]

Another simple solution:

ConstantDistribution[m_Real] := UniformDistribution[{m, m}]


ConstantDistribution[m_Integer] := DiscreteUniformDistribution[{m, m}]

For some reason Expectation works only with the discrete variant. Sampling works with both.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.