jeudi 2 septembre 2021

Python - How to create a list of floats when their sizes randomized within a specific range and their sum is predetermined

As written in the title I am interested in a simple way to produce a list of floats in length 'N, whose value ranges from 0.1 to 0.25 but whose sum will be fixed and predefined

Example a:

N = 9, sum = 1.575, list = (0.11, 0.24, 0.225, 0.16, 0.169, 0.233, 0.102, 0.2, 0.136)

Example B:

N = 2, Sum = 0.35, list = (0.2, 0.15)

Thanks!




Aucun commentaire:

Enregistrer un commentaire