ValueError: Sample larger than population or is negative的原因以及解决办法
1.出现
这几天重构kook-valorant-bot的代码的时候,遇到了这个问题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Job "vip_roll_task (trigger: interval[0:01:20], next run at: 2023-01-25 19:59:21 CST)" raised an exception Traceback (most recent call last): File "/home/muxue/.local/lib/python3.10/site-packages/apscheduler/executors/base_py3.py", line 30, in run_coroutine_job retval = await job.func(*job.args, **job.kwargs) File "/home/muxue/kook/val-bot/code/main.py", line 793, in vip_roll_task ran = random.sample(range(0, len(VipRollDcit[msg_id]['user']) - 1), vnum) File "/usr/local/lib/python3.10/random.py", line 482, in sample raise ValueError("Sample larger than population or is negative") ValueError: Sample larger than population or is negative error raised during task Traceback (most recent call last): File "/home/muxue/.local/lib/python3.10/site-packages/apscheduler/executors/base_py3.py", line 30, in run_coroutine_job retval = await job.func(*job.args, **job.kwargs) File "/home/muxue/kook/val-bot/code/main.py", line 793, in vip_roll_task ran = random.sample(range(0, len(VipRollDcit[msg_id]['user']) - 1), vnum) File "/usr/local/lib/python3.10/random.py", line 482, in sample raise ValueError("Sample larger than population or is negative") ValueError: Sample larger than population or is negative
$ py3 test1.py Traceback (most recent call last): File "/home/muxue/kook/test/global_val_test/test1.py", line 16, in <module> ran = random.sample(range(0, 2), 3) File "/usr/local/lib/python3.10/random.py", line 482, in sample raise ValueError("Sample larger than population or is negative") ValueError: Sample larger than population or is negative