【发布时间】:2013-05-29 06:24:24
【问题描述】:
当我尝试生成大小为 100 或更大的随机字符串时,它给了我异常...
msg="".join(random.sample(string.letters+string.digits,random.randint(5,100)))
Exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/random.py", line 316, in sample
raise ValueError, "sample larger than population"
ValueError: sample larger than population
您能帮我解释一下如何生成大小超过 100 的随机字符串吗? 还有为什么会出现这个异常?
【问题讨论】:
-
取决于你想比
100高多少...
标签: python string exception random size