Lottery Example
Model was written in NetLogo 5.0.4
•
Viewed 767 times
•
Downloaded 106 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
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 [ ;; vary the size of the turtles set size 2 + random 6 ;; start them out with no wins set label 0 ;; make turtles darker so the labels stand out set color color - 2 ] ] reset-ticks end to go ask lottery-winner [ set label label + 1 ] tick end ;; The idea behind this procedure is a bit tricky to understand. ;; Basically we take the sum of the sizes of the turtles, and ;; that's how many "tickets" we have in our lottery. Then we pick ;; a random "ticket" (a random number). Then we step through the ;; turtles to figure out which turtle holds that ticket. to-report lottery-winner let pick random-float sum [size] of turtles let winner nobody ask turtles [ ;; if there's no winner yet... if winner = nobody [ ifelse size > pick [ set winner self ] [ set pick pick - size ] ] ] report winner end ; Public Domain: ; To the extent possible under law, Uri Wilensky has waived all ; copyright and related or neighboring rights to this model.
There are 11 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Lottery Example.png | preview | Preview for 'Lottery Example' | over 11 years ago, by Uri Wilensky | Download |
This model does not have any ancestors.
This model does not have any descendants.