Oct-20-2021, 09:41 AM
Hello @deanhystad and @bowlofred and hello everyone,
This time, I need to generate random values between 0 and 1 which are successively ordered but following normal distribution. Their sum will be 1 again , I need to do exactly the same thing as you proposed before but the values should be normally distributed. How can I modify the code(s) you proposed ? Thank you so much in advance.
This time, I need to generate random values between 0 and 1 which are successively ordered but following normal distribution. Their sum will be 1 again , I need to do exactly the same thing as you proposed before but the values should be normally distributed. How can I modify the code(s) you proposed ? Thank you so much in advance.
(Oct-04-2021, 11:06 AM)juniorcoder Wrote:(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