你有 5 个选择,你想从这 5 个选择中随机选择。您将如何直接获取每个选择的数字,而不是模拟该选择 10 亿次?
这是模拟:
choices = [0, 0, 0, 0, 0]
for i in range (int(1e9)):
choices[random.randint(0, 4)] += 1
Run Code Online (Sandbox Code Playgroud)
但这非常慢,我不知道如何获得更快的解决方案。
老实说,我不知道我在看什么。
当我开始调试时,我在这个 VSCode 项目(一个 Discord 机器人)中的调试配置突然出现错误。正常运行程序的时候是不会这样的,其他项目调试好像还可以。
大约 50% 的时间,尽管出现错误并且调试正常,它最终会连接到 Discord,但其他时候程序会挂起并拒绝连接到 Discord。
这是错误文本,对于转储这么多代码,我深表歉意,但我不知道其中是否有任何重要意义:
'c:\Users\Lucas\.vscode\extensions\ms-python.python-2021.5.829140558\pythonFiles\lib\python\debugpy\launcher' '51717' '--' 'bot/bot.py'
pydev debugger: critical: unable to get real case for file. Details:
filename: bot
drive:
parts: ['bot']
(please create a ticket in the tracker to address this).
Traceback (most recent call last):
File "c:\Users\Lucas\.vscode\extensions\ms-python.python-2021.5.829140558\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydevd_file_utils.py", line 221, in _get_path_with_real_case
return _resolve_listing(drive, iter(parts))
File "c:\Users\Lucas\.vscode\extensions\ms-python.python-2021.5.829140558\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydevd_file_utils.py", line 184, in _resolve_listing
dir_contents = cache[resolved_lower] = os.listdir(resolved)
FileNotFoundError: [WinError 3] The system cannot find the path specified: ''
During handling …Run Code Online (Sandbox Code Playgroud)