【发布时间】:2015-01-16 09:27:45
【问题描述】:
如何使用概率表创建长度为K的N“随机”字符串? K 是偶数。
prob_table = {'aa': 0.2, 'ab': 0.3, 'ac': 0.5}
假设K = 6,'acacab' 的概率会高于'aaaaaa'。
这是我用来根据概率表生成合成序列的一个更大问题的子问题。我不确定如何使用概率表生成“随机”字符串?
到目前为止我所拥有的:
def seq_prob(fprob_table,K= 6, N= 10):
#fprob_table is the probability dictionary that you input
#K is the length of the sequence
#N is the amount of sequences
seq_list = []
#possibly using itertools or random to generate the semi-"random" strings based on the probabilities
return seq_list
【问题讨论】:
-
这是个好问题,随机模型序列真的很有用!
标签: python string random probability itertools