C#: Numerical algorithm to generate numbers from Binomial distribution

前端 未结 3 489
名媛妹妹
名媛妹妹 2021-01-17 22:59

I need to generate random numbers from Binomial(n,p) distribution.

A Binomial(n,p) random variable is sum of n uniform variables which take 1 with probability p. In

3条回答
  •  無奈伤痛
    2021-01-17 23:49

    Another option would be to sample from Normal or Poisson as you do and then add a Metropolis-Hastings step to accept or reject your sample. If you accept you are done, if you reject, you have to completely resample again. My guess is that because the approximation is so close, you will almost always get an accept step, once in a while you might reject.

    Also Luc Devroye's book has some great algorithms for Binomial sampling.

    PS If you end up with a good algorithm; would you mind sharing it at Math.Net Numerics?

提交回复
热议问题