Generate random numbers with a given (numerical) distribution

前端 未结 13 2007
我寻月下人不归
我寻月下人不归 2020-11-22 11:18

I have a file with some probabilities for different values e.g.:

1 0.1
2 0.05
3 0.05
4 0.2
5 0.4
6 0.2

I would like to generate random numb

相关标签:
13条回答
  • 2020-11-22 12:00

    Maybe it is kind of late. But you can use numpy.random.choice(), passing the p parameter:

    val = numpy.random.choice(numpy.arange(1, 7), p=[0.1, 0.05, 0.05, 0.2, 0.4, 0.2])
    
    0 讨论(0)
提交回复
热议问题