# Distributions.jl is there a deterministic distribution?

**URL:** <https://discourse.julialang.org/t/distributions-jl-is-there-a-deterministic-distribution/32475>\
**Category:** Statistics\
**Created:** [December 19, 2019, 10:38am UTC](https://discourse.julialang.org/t/distributions-jl-is-there-a-deterministic-distribution/32475 "2019-12-19T10:38:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![HenriDeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrideh/32/8316_2.png) [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)\
**Post date:** [December 19, 2019, 10:38am UTC](https://discourse.julialang.org/t/distributions-jl-is-there-a-deterministic-distribution/32475/1 "2019-12-19T10:38:33Z")

</div>

I’m working with a structure that has a Distribution field. However I would like it to be able to also take a fixed value without the need to make a `Union{Distribution,Real}` field type. I think the Dirac distribution does that ? But unless I’m mistaken it is not present in the package. Is there an equivalent whose name I’m not aware of ?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [December 19, 2019, 11:10am UTC](https://discourse.julialang.org/t/distributions-jl-is-there-a-deterministic-distribution/32475/2 "2019-12-19T11:10:46Z")

</div>

> [@HenriDeh](#):
>
> I would like it to be able to also take a fixed value without the need

I don’t really understand your question but if you’re asking for a fixed sample, all you need to do is set the seed to the same value every time before sampling:

```julia
julia> using Random, Distributions

julia> Random.seed!(123) # Setting the seed

```

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [December 19, 2019, 11:12am UTC](https://discourse.julialang.org/t/distributions-jl-is-there-a-deterministic-distribution/32475/3 "2019-12-19T11:12:14Z")

</div>

There doesn’t seem to be, but it could certainly be added. I would file an issue on the repo.

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [December 19, 2019, 11:50am UTC](https://discourse.julialang.org/t/distributions-jl-is-there-a-deterministic-distribution/32475/4 "2019-12-19T11:50:07Z")

</div>

If I understand your question correctly, I think you can define your own custom distribution type:

```julia
import Distributions: ContinuousUnivariateDistribution
import Base: rand

struct Fixed{T<:Real} <: ContinuousUnivariateDistribution
    x::T
end

function rand(dist::Fixed)
    return dist.x
end

dist = Fixed(1.0)

```

Example:

```julia
julia> rand(dist)
1.0

```

---

<div class="post-metadata">

**Author:** ![HenriDeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrideh/32/8316_2.png) [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)\
**Post date:** [December 19, 2019, 1:18pm UTC](https://discourse.julialang.org/t/distributions-jl-is-there-a-deterministic-distribution/32475/5 "2019-12-19T13:18:37Z")

</div>

Yes that’s the sort of behavior I’m looking for. There’s no native equivalent apparently says @StefanKarpinski , that’s what I wanted to know. I’ll ask on the repo if this could be added.
