# Do I need to define a random Sampler?

**URL:** <https://discourse.julialang.org/t/do-i-need-to-define-a-random-sampler/36925>\
**Category:** General Usage\
**Tags:** question\
**Created:** [April 2, 2020, 10:27pm UTC](https://discourse.julialang.org/t/do-i-need-to-define-a-random-sampler/36925 "2020-04-02T22:27:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChandlerKilpatrick1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chandlerkilpatrick1/32/21207_2.png) [@ChandlerKilpatrick1](https://discourse.julialang.org/u/ChandlerKilpatrick1)\
**Post date:** [April 2, 2020, 10:27pm UTC](https://discourse.julialang.org/t/do-i-need-to-define-a-random-sampler/36925/1 "2020-04-02T22:27:57Z")

</div>

Hey all, I am getting the following error when I run my code:

```julia
ERROR: LoadError: MethodError: no method matching &(::TagState, ::UInt8)
Closest candidates are:
  &(::Any, ::Any, ::Any, ::Any...) at operators.jl:529
  &(::Missing, ::Integer) at missing.jl:157
  &(::T, ::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8} at int.jl:293
  ...
Stacktrace:
 [1] randexp(::MersenneTwister) at /Users/sabae/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/Random/src/normal.jl:101
 [2] efraimidis_aexpj_wsample_norep!(::MersenneTwister, ::Array{}, ::Array{}) at /Users/chandlerkilpatrick/.julia/packages/StatsBase/DyWPR/src/sampling.jl:715
 [3] #sample!#153(::Bool, ::Bool, ::typeof(sample!), ::MersenneTwister, ::Array{{TagState},1}, ::StatsBase.ProbabilityWeights{Float64,Float64,Array{Float64,1}}, ::Array{{TagState},1}) at /Users/chandlerkilpatrick/.julia/packages/StatsBase/DyWPR/src/sampling.jl:775

```

Is this indicative of the fact that I need to write a custom Random sampler or is there something else going on here?

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [April 2, 2020, 10:33pm UTC](https://discourse.julialang.org/t/do-i-need-to-define-a-random-sampler/36925/2 "2020-04-02T22:33:14Z")

</div>

Would definitely help if you post a full MWE or at a minimum the line that errors.

---

<div class="post-metadata">

**Author:** ![ChandlerKilpatrick1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chandlerkilpatrick1/32/21207_2.png) [@ChandlerKilpatrick1](https://discourse.julialang.org/u/ChandlerKilpatrick1)\
**Post date:** [April 2, 2020, 10:35pm UTC](https://discourse.julialang.org/t/do-i-need-to-define-a-random-sampler/36925/3 "2020-04-02T22:35:36Z")

</div>

It is confidential code sadly which makes it hard to get help on this stuff. What I can say is that the error propagates from when I call: `StatsBase.sample()`. I will update above with a little more of the stack trace.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 3, 2020, 5:27am UTC](https://discourse.julialang.org/t/do-i-need-to-define-a-random-sampler/36925/4 "2020-04-03T05:27:15Z")

</div>

> [@ChandlerKilpatrick1](#):
>
> Is this indicative of the fact that I need to write a custom Random sampler or is there something else going on here?

It is difficult to answer this from the code you posted.
