In a Python program, I need to generate normally-distributed random numbers with a specific, user-controlled variance. How can I do this?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Use
random.normalvariate
(orrandom.gauss
if you don't need thread-safety), and set thesigma
argument to the square root of the variance.This gets you 100 normally-distributed random numbers with mean 0 and variance 10.