Python: Random number generator with mean and Standard Deviation

后端 未结 2 892
盖世英雄少女心
盖世英雄少女心 2020-12-15 12:28

I need to know how to generate 1000 random numbers between 500 and 600 that has a mean = 550 and standard deviation = 30 in python.

import pylab
import rand         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 12:41

    You are looking for stats.truncnorm:

    import scipy.stats as stats
    
    a, b = 500, 600
    mu, sigma = 550, 30
    dist = stats.truncnorm((a - mu) / sigma, (b - mu) / sigma, loc=mu, scale=sigma)
    
    values = dist.rvs(1000)
    

提交回复
热议问题