rnd:weighted-one-of
rnd:weighted-one-of agentset reporter
Reports a random agent from agentset.
The probability of each agent being picked is proportional to the weight given by the reporter for that agent. The weights must not be negative.
If the agentset is empty, it reports nobody
.
Here is a full rewrite of the Lottery Example model using the rnd:weighted-one-of
primitive:
extensions [ rnd ]
to setup
clear-all
; create a turtle on every fifth patch
ask patches with [ pxcor mod 5 = 0 and pycor mod 5 = 0 ] [
sprout 1 [
set size 2 + random 6 ; vary the size of the turtles
set label 0 ; start them out with no wins
set color color - 2 ; make turtles darker so the labels stand out
]
]
reset-ticks
end
to go
ask rnd:weighted-one-of turtles [ size ] [
set label label + 1
]
tick
end
Take me to the full Rnd Extension Dictionary