Oct-04-2021, 11:06 AM
(This post was last modified: Oct-04-2021, 11:07 AM by juniorcoder.)
(Oct-03-2021, 01:02 PM)deanhystad Wrote: To avoid 0 I would use random.sample(). It guarantees each value is unique.
import random def random_divisions(n, total_size=100): values = sorted([0, total_size] + random.sample(range(total_size), n-1)) return sorted([(y-x)/total_size for x,y in zip(values , values [1:])]) r = random_divisions(5) print(f"{r} {sum(r)}")
Output:[0.03, 0.04, 0.24, 0.33, 0.36] 1.0
Thank you so much @deanhystad. I guess now, it has been solved