jeudi 3 mars 2022

Creating a random sample with the sum of the elements lower than 100 - Python

I want to create a random sample of 20 numbers with the constraint that the sum of the numbers must be between 0 and 100

I know how to create the random sample - how can I set my constraints?

import random

#Generate 5 random numbers between 10 and 100 for a list of 20 elements
randomlist = random.sample(range(0, 100), 20)
print(sum(randomlist))



Aucun commentaire:

Enregistrer un commentaire