Issue
Could someone explain to me how I can use random to generate a list consisting of numbers that differ from 0 to 9 and the size should be fixed between 49 and 98?
random_number = [random.randint(0,9) for _ in range()]
I think I should use this line, but I am not sure how to limit the random_number which gets generated to be a number consisting of 49 to 98 numbers.
Could someone help me clarifying this?
Solution
You can use random.choices
to generate a list of random entries from a range, pass k=
to determine the size. We can pass k=random.randint(49, 98)
to generate a list with a random length in that range
import random
random.choices(range(0, 9), k=random.randint(49, 98))
Answered By - Iain Shelvington
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.