Is there any way to take multiple values with "random.randrange"? Like in random.choices or random.sample we can choose more than 1 element with "k".
import random
print("3 values divided by 3")
print(random.randrange(100,999,5,k=3,end=','))
Is there any way to take multiple values with "random.randrange"? Like in random.choices or random.sample we can choose more than 1 element with "k".
import random
print("3 values divided by 3")
print(random.randrange(100,999,5,k=3,end=','))
There aren't specific functions to do this in the random
module, but look at the docs for randrange()
:
This is equivalent to
choice(range(start, stop, step))
, but doesn't actually build a range object.
Therefore, just do choices(range(...), k=3)
or sample(range(...), k=3)
.
Note: In Python 3, this will be memory-efficient since range
is lazy. In Python 2, I believe xrange
behaves the same.