0

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!

Mira Fey
  • 49
  • 5

1 Answers1

2

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

Luke C
  • 10,081
  • 1
  • 14
  • 21
  • Thanks so much! I used one-of, but wasn't sure if this was distributing it randomly, or instead just 1/2 each. But it seems it is random? – Mira Fey Nov 28 '18 at 22:32
  • @MiraFey - Yep, good instinct- it is random. Check out the [one-of dictionary entry](http://ccl.northwestern.edu/netlogo/docs/dict/one-of.html) for the more details. – Luke C Nov 28 '18 at 22:35
  • Thanks so much, that is great to know! This works well now! Still a lot left to code for the model, but at least the setup is as I want it now. – Mira Fey Nov 28 '18 at 22:39
  • @MiraFey - Excellent, happy coding! – Luke C Nov 28 '18 at 22:40