Sampling from custom distribution: "No method matching iterate..."

The main problem is that you need to import the methods, including rand in order to extend them. Try the following:

using Distributions 
import Distributions: logpdf, rand, maximum, minimum
using Random 

struct MyUniformDist <: ContinuousUnivariateDistribution
    L::Real
end
logpdf(d::MyUniformDist, x::Real) = 0 ≤ x ≤ d.L ? log(1/d.L) : -Inf
rand(rng::AbstractRNG, d::MyUniformDist) = rand(rng) * d.L
minimum(d::MyUniformDist) = 0.
maximum(d::MyUniformDist) = d.L

foo = MyUniformDist(3)
rand(foo)
1 Like