Python - 为采样整数创建偏态离散正态概率分布

Python - Creating a skewed discrete normal probability distribution for sampling integers

类似于下面的问题:
Create random numbers with left skewed probability distribution

通过说明最大值和方差,我想从某个给定范围内采样整数。

例如,对于范围 - {0,1,...,1000}(也称为 range(1001)),最大值为 100,因此采样数字最有可能来自 [ 90-110],不太可能被采样的数字是 [80-89] 和 [111-120] 等

以下代码将执行此操作:

import scipy.stats as ss
import numpy as np
import matplotlib.pyplot as plt

center = 100
n = 1001
std = 20
x = np.arange(0, n)
prob = ss.norm.pdf(x,loc=center, scale = std )
prob = prob / prob.sum() #normalize the probabilities so their sum is 1    

nums = np.random.choice(x, 20, p=prob)
nums