我想生成一组随机坐标,其中x和y在(0,2)范围内。允许重复一种组合。我尝试了以下代码。
possible_coordinates = [(x, y) for x in range(3) for y in range(0,2)]
bomb_coordinates = random.sample(possible_coordinates, k=70)
给出期望的结果,直到K = 6,其中k是所需的坐标对数。但是当k超过6时,它将在random.py中给出错误。
请帮助我生成50对随机坐标。
Traceback
<module> C:\Users\TOSHIBA\Desktop\mypython\to be corrected\run_para.py 12
sample C:\Users\TOSHIBA\AppData\Local\Programs\Python\Python37\Lib\random.py 321
ValueError: Sample larger than population or is negative