How to generate a random integer as with np.random.randint()
, but with a normal distribution around 0.
np.random.randint(-10, 10)
returns integers with a discrete uniform distribution
np.random.normal(0, 0.1, 1)
returns floats with a normal distribution
What I want is a kind of combination between the two functions.
One other possible way to get a discrete distribution that looks like the normal distribution is to draw from a multinomial distribution where the probabilities are calculated from a normal distribution.
Here,
np.random.choice
picks an integer from [-10, 10]. The probability for selecting an element, say 0, is calculated by p(-0.5 < x < 0.5) where x is a normal random variable with mean zero and standard deviation 3. I chooce std. dev. as 3 because this way p(-10 < x < 10) is almost 1.The result looks like this:
It may be possible to generate a similar distribution from a Truncated Normal Distribution that is rounded up to integers. Here's an example with scipy's truncnorm().
Let's see what it looks like
Here we start by getting values from the bell curve.
CODE:
OUTPUT: