随机数 - 有没有用Python生成n个不重复随机坐标的算法?
迷茫
迷茫 2017-04-18 10:23:28
0
2
945

有没有用Python生成n个不重复随机坐标的算法?比如范围(5,3)内的坐标:
1 2
1 3
2 2
2 3
等等

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all (2)
洪涛

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)
    洪涛
    import random n = 5 for x in random.sample(range(3 * 5), n): print('({}, {})'.format(*pmod(x, 3)))
      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!