Generating numbers with Gaussian function in a range using python -


i want use gaussian function in python generate numbers between specific range giving mean , variance

so lets have range between 0 , 10

and want mean 3 , variance 4

mean = 3, variance = 4

how can ?

use random.gauss. docs:

random.gauss(mu, sigma)     gaussian distribution. mu mean, , sigma standard deviation.     faster normalvariate() function defined below. 

it seems me can clamp results of this, wouldn't make gaussian distribution. don't think can satisfy constraints simultaneously. if want clamp range [0, 10], numbers:

num = min(10, max(0, random.gauss(3, 4))) 

but resulting distribution of numbers won't gaussian. in case, seems can't have cake , eat it, too.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -