samedi 9 novembre 2019

Python: generate a list of unique random numbers having a min and max amount of digits

I would like to create a function that returns a list of unique random numbers having a min and max amount of digits.

I could use sample of random to create a list of unique random numbers but I have to pass a range. I would like to modify it to pass a min and max amount of digits.

For example min amount of digits is 1 and max amount of digits is 4

So it should create a random number in the range of (0, 9999)

Or if the min and max are both 1 it should create a list of random unique numbers in the range of (0, 9)

I was trying to do

from random import sample

sample(range(x,y), k)

But my problem is now how to convert the min and max amount of digits to a range




Aucun commentaire:

Enregistrer un commentaire