I am trying to draw a random index from a vector of probabilities. Here is my code:

```
import Random
using Random: AbstractRNG
struct FastCategorical
_cdf::Vector{Float64}
function FastCategorical(pdf)
cdf = cumsum(pdf)
@assert last(cdf) ≈ 1
new(cdf)
end
end
@inline function Random.rand(rng::AbstractRNG, o::FastCategorical)
p = rand(rng)
searchsortedfirst(o._cdf, p)
end
using BenchmarkTools
using LinearAlgebra
pdf = normalize!(rand(10^5), 1)
d = FastCategorical(pdf)
rng = Random.GLOBAL_RNG
@btime rand($rng, $d) # 128.708 ns (0 allocations: 0 bytes)
@btime searchsortedfirst($(d._cdf), x) setup=(x = rand()) # 39.083 ns (0 allocations: 0 bytes)
@btime rand($(rng)) # 2.865 ns (0 allocations: 0 bytes)
```

Observe that `rand`

is much slower then running both its lines individually.