I'd like to assign a random boolean variable to each turtle, but I'm not seeing a function that would simulate a draw from a Bernoulli distribution.
This gets close, but it's awkward:
ifelse random-in-range 0 1 < .5 [set expensive? false]
[ set expensive? true ]
Anyone know a better way?
A few options:
If I deal with a lot of probabilistic stuff in a model, I like to add
to-report probability [ p ]
report random-float 1 < p
end
as an easy shorthand.
Also, note that the ifelse
is redundant in your code. You can just do set expensive? one-of [ true false ]
or whichever is your preferred method.