I am trying to use probability to assign [0] or [1] individual values for a turtles-own variable in NetLogo, but have only found ways of printing or reporting probability outputs rather than using them to determine a variable value.
Example:
I am asking two turtles to check whether they each want to exchange information with each other, and have assigned a variable exchangeinfo. If exchangeinfo = 0, then no information exchange happens. If exchangeinfo = 1, then information exchange occurs.
Currently I've hard-coded [set exchangeinfo 1] as a placeholder.
But I'd like each turtle to have a 25% chance of exchangeinfo = 1, but I do not want to set variables one at a time.
Any suggestions?
@Alan's comment will work. Here is a super simple model that will do what I think you're asking.
turtles-own[exchangeinfo]
to setup
clear-all
reset-ticks
make_turtles
end
to go
move
tick
if (ticks = 1) [inspect turtle 1]
end
to make_turtles
create-turtles 10
ask turtles
[
set color pink
set size 2
set xcor random max-pxcor
set ycor random max-pycor
set exchangeinfo 0
]
end
to move
ask turtles
[right random-float 270
forward random-float 3
if ((count (turtles in-radius 2)) > 0)
[move-to one-of turtles in-radius 2]
]
encounter ;<- this is the function that will decide whether or not to exchange info.
end
to encounter
ask turtles[
if (count turtles-here > 0)
[ifelse (random-float 1 < 0.25) ;note this is essentially @Alan's answer
[set exchangeinfo 1]
[set exchangeinfo 0]
]
]
end
I'm assuming you'll then want some sort of
ask turtles-here [if (exchangeinfo = 1) [do stuff]]
as well