Lottery Example

Lottery Example preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

code example 

Tagged by Reuven M. Lerner almost 12 years ago

probability 

Tagged by Reuven M. Lerner over 11 years ago

random 

Tagged by Reuven M. Lerner over 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 767 times • Downloaded 106 times • Run 0 times
Download the 'Lottery Example' modelDownload this modelEmbed this model

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.

Uploaded by When Description Download
Uri Wilensky over 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky about 12 years ago Updated version tag Download this version
Uri Wilensky about 12 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky almost 13 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago Lottery Example Download this version
Uri Wilensky over 14 years ago Lottery Example Download this version

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.