Farsi / Persian
NetLogo Models Library:
Note: If you download the NetLogo application, every model in the Models Library is included.
This example demonstrates the use of the
rnd extension to do weighted random selection.
We create as many turtles as there are base colors in NetLogo (i.e., 14) and align them horizontally on the screen. Initially, all turtles have size 1. At each tick we randomly pick one turtle and increase its size by 1. The model stops when the total width of the turtles is enough to horizontally fill the world.
The model offers two ways to randomly select turtles. When WEIGHTED-SELECTION? is turned off, the selection is done in a uniform fashion, using
one-of turtles, and each turtle has the same probability of being picked. When WEIGHTED-SELECTION? is turned on, we use
rnd:weighted-one-of turtles [ size ] instead, so bigger turtles stand a greater chance of being picked. For example, a turtle with size 2 is twice as likely to be picked as a turtle with size 1.
Press SETUP to initialize the model and GO to run it.
The WEIGHTED-SELECTION? switch control whether or not the random selection is proportional to the size of the turtle.
The TURTLE SIZES bar plot shows the size of each turtle, in decreasing order.
Try a few runs with WEIGHTED-SELECTION? turned on, and then a few runs where it's turned off. Can you notice the change in the distribution of sizes in the TURTLE SIZES plot?
The Lottery Example model achieves a very similar thing using only regular NetLogo primitives. Can you think of a way to rewrite the Lottery Example model using the