Generate random numbers according to distributions

前端 未结 6 751
谎友^
谎友^ 2020-12-05 07:45

I want to generate random numbers according some distributions. How can I do this?

6条回答
  •  一向
    一向 (楼主)
    2020-12-05 08:43

    The right way to do this is to decompose the distribution into n-1 binary distributions. That is if you have a distribution like this:

    A: 0.05
    B: 0.10
    C: 0.10
    D: 0.20
    E: 0.55
    

    You transform it into 4 binary distributions:

    1. A/E: 0.20/0.80
    2. B/E: 0.40/0.60
    3. C/E: 0.40/0.60
    4. D/E: 0.80/0.20
    

    Select uniformly from the n-1 distributions, and then select the first or second symbol based on the probability if each in the binary distribution.

    Code for this is here

提交回复
热议问题