I am writing a model with two breeds: sexworkers and officers where sexworkers possess a boolean variable that is randomly distributed at the setup, but then changes at the go according to the behavior of and interaction with officers. I use sexworkers-own [ trust? ]
in the preamble, but then I am not sure how to distribute y/n of the variable randomly across the sexworkers population. Really appreciate any input!
Thank you so much!
If I understand your question correctly, you're just wanting sexworkers
to randomly choose between true
and false
for the trust?
variable on setup. If that's right, then maybe one-of
will do the trick for you- for an example, run this simple setup:
breed [ sexworkers sexworker ]
sexworkers-own [ trust? ]
to setup
ca
create-sexworkers 1000 [
set trust? one-of [ true false ]
]
print word "% Trusting: " ( ( count sexworkers with [ trust? ] ) /
count sexworkers * 100 )
reset-ticks
end
If you're looking for some kind of uneven distribution you can do simple ones using the random
or random-float
primitives. For example, if I want 25% of the sexworkers
to start with trust? = true
, I can do something like:
to setup-2
ca
create-sexworkers 1000 [
ifelse random-float 1 < 0.25 [
set trust? true
] [
set trust? false
]
]
print word "% Trusting: " ( ( count sexworkers with [ trust? ] ) /
count sexworkers * 100 )
reset-ticks
end
For specific distributions, have a look at the various random reporters
For weighted randomness, have a look at the rnd
extension