“sample larger than population” in random.sample python

前端 未结 3 1992
隐瞒了意图╮
隐瞒了意图╮ 2020-12-16 00:31

creating a simple pass generator for myself, i noticed that if i want my population to be digits only (0-9) which is overall 10 options, if i want my length over 10, it wont

3条回答
  •  不知归路
    2020-12-16 01:13

    Since the python_3.6 you can use random.choises(x, k=v) for your purpose. It returns a k sized list of elements chosen from the population with replacement. If the population is empty, raises IndexError.

提交回复
热议问题