lundi 21 novembre 2016

Generate a random list with the desired total sum

I want to create from 1 to 4 blocks of water with randint(1,4) with a certain surface (the surface has to be generated). But these blocks of water must have a total surface of 100m2.

I planned to add the blocks of water(with random surfaces) to a list, and make the sum of the list equal to 100.

Is this the way to tackle this problem? If yes, how do I do this?

It has to be something like this:

list1 = [surface1,  surface2, surface3, surface4]

The surfaces are unknown though, but I have to make the surfaces add up to 100.

So:

sum(list1) == 100

How do I do generate the surfaces to add up to 100?




Aucun commentaire:

Enregistrer un commentaire