function randSizeBiasedNegativeBinomial(r,p,n)
@argcheck isa(r, Int) & (r ≥ 1)
@argcheck (p ≤ 1) & (p ≥ 0)
@argcheck isa(n, Int) & (n ≥ 1)
u = rand(MersenneTwister(),n,1)
mu = r*(1-p)/p + 1 # why is +1 necessary? Because the support starts from 0?
M = repeat(transpose(1:100),n,1) # why is size(M,2) set at 100?
x = sum(cumsum((1 .- cdf.(NegativeBinomial(r,p),M.-2)),dims=2)/mu .<= repeat(u,1,size(M,2)), dims=2) .+ 1 # why M.-2 and why .+ 1
return x
end
Questions for @LloydChapman added as comments