有没有用Python生成n个不重复随机坐标的算法?比如范围(5,3)内的坐标:
1 2
1 3
2 2
2 3
等等
PHP中文网2017-04-18 10:25:28
python 3
import itertools
list(itertools.product(range(1, 6), range(1, 4)))
If randomization is needed, just randomly generate the index in the above list
import random
n = 5
random_list = list(itertools.product(range(1, 6), range(1, 4)))
random.sample(random_list, n)
PHP中文网2017-04-18 10:25:28
import random
n = 5
for x in random.sample(range(3 * 5), n):
print('({}, {})'.format(*pmod(x, 3)))