Ale
Ale

Reputation: 107

Creating random numbers that add to 1 in Netlogo

I am trying to generate a list of random numbers that must all add to 1 (or 100 if that's easier) but can't figure out how to do it. I know Netlogo allows you to create random numbers but can't find a way to set the rule that the addition of the generated numbers must be 1. Any help is much appreciated!

Upvotes: 3

Views: 94

Answers (1)

Nicolas Payette
Nicolas Payette

Reputation: 14972

Something like this?

let xs n-values 5 [ -> random-float 1 ]
let total sum xs
set xs map [ x -> x / total ] xs

Upvotes: 4

Related Questions