# Lottery Example

### 1 collaborator

Uri Wilensky (Author)

### Tags

code example

Tagged by Reuven M. Lerner about 11 years ago

probability

Tagged by Reuven M. Lerner about 11 years ago

random

Tagged by Reuven M. Lerner about 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 647 times • Downloaded 84 times • Run 0 times

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
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
[ ;; 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.

Uri Wilensky almost 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky over 11 years ago Updated version tag Download this version
Uri Wilensky over 11 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky over 12 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Model from NetLogo distribution Download this version