如何使用高斯分布打乱列表

nic*_*anc 3 python random simulator gaussian fault

我想模拟一条消息的错误(例如:1000010011 => 1010000011)。有没有办法在 Python 中实现它?我尝试了以下方法,该方法有效:

import random
a = "1011101101"
b = [el for el in a] # b = ['1', '0', '1', '1', '1', '0', '1', '1', '0', '1']
random.shuffle(b)
print b # b = ['0', '1', '1', '1', '0', '1', '1', '1', '1', '0']
random.shuffle(b, random.random)
print b # b = ['1', '1', '0', '1', '1', '0', '1', '0', '1', '1']
Run Code Online (Sandbox Code Playgroud)

我希望我的重新排序是正态/高斯分布的。例如:

import random
a = "1011101101"
b = [el for el in a] # b = ['1', '0', '1', '1', '1', '0', '1', '1', '0', '1']
random.shuffle(b,random.gauss(0.5,0.1))
print b # b = ['1', '0', '1', '1', '0', '0', '1', '1', '1', '1'] <= assume this is Gaussian distributed...
# OR
c = random.gauss(0.5,0.1)
random.shuffle(b,c)
print b # b = ['0', '0', '1', '1', '1', '0', '1', '1', '1', '1'] <= assume this is also Gaussian distributed...
Run Code Online (Sandbox Code Playgroud)

但是,这不起作用,我收到消息:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\random.py", line 287, in shuffle
    j = int(random() * (i+1))
TypeError: 'float' object is not callable
Run Code Online (Sandbox Code Playgroud)

任何建议/评论将不胜感激。

谢谢

注意:我只是在这里要求重新排序错误(例如:1000010011 => 1010000011)。但是,我还计划模拟突发错误(例如:1000010011 => 1011111011)、单个事件(例如:1000010011 => 1000010011)等。

其他相关问题:Python: binary string error simulation

E.Z*_*.Z. 5

c = lambda: random.gauss(0.5,0.1)
Run Code Online (Sandbox Code Playgroud)