jeudi 20 décembre 2018

Generate random integer number wiht normal disterbution in python

I am a beginner in Python and have a simple question. I want to generate 10 integer random number between -2 and 2 with normal distribution. I read some similar question in SOF but really confused with the answers.After all, tried this:

import numpy as np
x = np.random.normal(0, 0.5, 10)

for i in range(0,9):
    print (int(x[i]))

I guess 0.5 for standard deviation and 0 for expectation. But output seems wrong: generally print 0s and some 1 or -1. Is there any way to generate integer number with normal distribution and range(-2, 2) setting? If not, can help me with mentioned code?




Aucun commentaire:

Enregistrer un commentaire