Random Walk Left Right
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
This is a model to simulate a random walk. In this simulation, all turtles walk to the left and forward or they walk to the right and forward. The turtles randomly choose between either direction each time they move.
The path traced out by the turtles moving in this pattern is called a lattice.
HOW IT WORKS
As the simulation continues, one can expect the turtles to become more spread out. Observe the kinds of patterns that develop as the turtles move.
Shading of turtles is representative of how many turtles share that location. Dark shades imply more turtles. Light shades imply fewer turtles.
For purposes of this simulation, "forward" will mean moving toward the top of the view, "left" will mean moving toward the left edge of the view, and "right" will mean moving toward the right edge of the view.
HOW TO USE IT
Use the NUMBER-OF-TURTLES slider to select how many turtles will participate in the random walk.
Use the NUMBER-OF-STEPS slider to decide how many steps a turtle will take on each turn.
How steps are implemented:
- If NUMBER-OF-STEPS is set to 1 and a turtle is going left, it will go left one step and then go forward one step. (Imagine a turtle walking along the bottom and left edge of a 1 x 1 square.)
- If NUMBER-OF-STEPS is set to 4 and a turtle is going left, it will go left four steps and then go forward four steps. (Imagine a turtle walking along the bottom and left edge of a 4 x 4 square.)
- Each of the above movements would be considered a single "pace."
Use the TURTLE-TRAILS? switch to have the turtles put their pens down to trace their paths and show the part of the lattice they are covering. This switch must be set before the SETUP button is pressed.
All sliders except NUMBER-OF-TURTLES may be changed during a simulation.
Press the SETUP when all of the above selections have been made. This will create the selected number of turtles at the bottom center of the world.
Press GO ONCE button to make the turtles move one pace.
Press the GO button to make the turtles move until one of the turtles cannot complete its number of steps. When one turtle reaches this point, all the other turtles will stop even if they can complete the step.
To stop the simulation while it is running, press the GO button again.
The gray bar in the middle of the world is at xcor = 0. This is where all the turtles start.
THINGS TO TRY
Try to answer the questions below before running the simulations.
Record your predictions. Compare your predicted results with the actual results.
- What reasoning led you to correct predictions?
- What assumptions that you made need to be revised?
Try different numbers of turtles while keeping all other slider values the same.
Try different numbers of steps while keeping all other slider values the same.
THINGS TO NOTICE
Think about how you would define an "average" turtle and an "average" walk.
Where would you expect an average turtle to end up at the end of the simulation? Why?
How many paces would you expect there to be in an average walk? Why?
What kinds of calculations or measurements would you use in trying to answer these questions?
How do your answers to the above questions compare to the average of the x coordinates of all the turtles?
EXTENDING THE MODEL
As the model stands, it plots two lines (right and left) over time. Another way to look at this simulation is to plot the distribution of turtles. Create a histogram to show this type of data.
The turtles will stop if they come up to an obstacle (cannot move forward or to the right/left), give the turtles the ability to think ahead and choose a different step/direction.
Give the turtles the ability to walk backwards.
Create a three dimensional lattice.
NETLOGO FEATURES
Since turtles in this model only move in the positive direction and they start at the bottom the origin is relocated to be at the bottom of the view also, so there are no patches with negative pycor.
RELATED MODELS
Random Walk 360, Galton Box, Binomial Rabbits
HOW TO CITE
If you mention this model in a publication, we ask that you include these citations for the model itself and for the NetLogo software:
- Wilensky, U. (1997). NetLogo Random Walk Left Right model. http://ccl.northwestern.edu/netlogo/models/RandomWalkLeftRight. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.
- Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.
COPYRIGHT AND LICENSE
Copyright 1997 Uri Wilensky.
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.
This model was created as part of the project: CONNECTED MATHEMATICS: MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL MODELS (OBPML). The project gratefully acknowledges the support of the National Science Foundation (Applications of Advanced Technologies Program) -- grant numbers RED #9552950 and REC #9632612.
This model was converted to NetLogo as part of the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. The project gratefully acknowledges the support of the National Science Foundation (REPP & ROLE programs) -- grant numbers REC #9814682 and REC-0126227. Converted from StarLogoT to NetLogo, 2002.
Comments and Questions
;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; variable declarations ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;; globals [ num-turtles-right ;; how many turned right this tick num-turtles-left ;; how many turned left this tick sum-right-turns ;; the sum of turtles that turned right for the entire run sum-left-turns ;; the sum of turtles that turned left for the entire run ] ;;;;;;;;;;;;;;;;;;;;;; ;; setup procedures ;; ;;;;;;;;;;;;;;;;;;;;;; ;; sets up the patches and creates turtles to setup clear-all ask patches [ set pcolor gray + 3 ] draw-line-up-middle setup-turtles init-vars reset-ticks end ;; draw a line up the middle to draw-line-up-middle crt 1 [ set heading 0 set pen-size 3 set pcolor 8 pd fd world-height die ] end ;; determines the number of turtles and their color ;; if turtle-trails? is on, the turtles' pens should be down, ;; otherwise they should be up to setup-turtles ;; the origin is at the bottom of the view so there is no need ;; to relocate the turtles upon creation crt number-of-turtles [ set color black set pen-size 3 ifelse turtle-trails? [ pd ] ;; have the turtles put down their pens [ pu ] ;; have the turtles pick up their pens set heading 0 ] end ;; counts the number of right and left turns and paces of the turtles to init-vars set sum-right-turns 0 set sum-left-turns 0 end ;;;;;;;;;;;;;;;;;;;;;;;; ;; runtime procedures ;; ;;;;;;;;;;;;;;;;;;;;;;;; ;; have the turtles randomly pick either right or left and ;; have them move in that direction ;; if one turtle cannot move, then stop to go set num-turtles-right 0 ;; the number of turtles turning right currently set num-turtles-left 0 ;; the number of turtles turning left currently ;; if one turtles cannot move because it is at the edge of the world, then stop if any? turtles with [ patch-at 0 number-of-steps = nobody or patch-at (- number-of-steps) 0 = nobody or patch-at number-of-steps 0 = nobody ] [ stop ] ask turtles [ ifelse ((random 2) = 0) [ go-left set num-turtles-left (num-turtles-left + 1) ] [ go-right set num-turtles-right (num-turtles-right + 1) ] ;; set the color of the turtles to give a rough idea of how many turtles ;; are at each location -- the lighter the color, the greater the number ;; of turtles set color scale-color blue (count turtles-here) (number-of-turtles / 5) 0 ] ;; update the sums of right and left turns set sum-right-turns (sum-right-turns + num-turtles-right) set sum-left-turns (sum-left-turns + num-turtles-left) tick end ;; turn left and go one-pace to go-left ;; turtle procedure lt 90 one-pace end ;; go forward number-of-steps, turn upwards and go forward number-of-steps to one-pace ;; turtle procedure fd number-of-steps set heading 0 fd number-of-steps end ;; turn right and go one-pace to go-right ;; turtle procedure rt 90 one-pace end ; Copyright 1997 Uri Wilensky. ; See Info tab for full copyright and license.
There are 10 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Random Walk Left Right.png | preview | Preview for 'Random Walk Left Right' | over 11 years ago, by Uri Wilensky | Download |
This model does not have any ancestors.
This model does not have any descendants.