Distributed probability random number generator

前端 未结 7 1053
挽巷
挽巷 2020-12-05 10:47

I want to generate a number based on a distributed probability. For example, just say there are the following occurences of each numbers:

Number| Count               


        
7条回答
  •  萌比男神i
    2020-12-05 11:14

    The general approach is to feed uniformly distributed random numbers from 0..1 interval into the inverse of the cumulative distribution function of your desired distribution.

    Thus in your case, just draw a random number x from 0..1 (for example with Random.NextDouble()) and based on its value return

    • 1 if 0 <= x < 150/208,
    • 2 if 150/208 <= x < 190/208,
    • 3 if 190/208 <= x < 205/208 and
    • 4 otherwise.

提交回复
热议问题