CS110A Week 16 Day 2 lesson on Thursday 12/03/2026.
Overview
Indika Walimuni teaches a Python turtle simulation of a randomly moving drunkard, then introduces internet communication concepts including TCP, UDP, routers, IP addresses, DNS, and IPv4 versus IPv6. The programming exercise uses random step lengths of 2 to 5, four equally likely turn choices, and a circular boundary checked with the equation x² + y² = r².
Key takeaways
- A drunkard-walk simulation can use random.randint(2, 5) for movement length and random.randint(1, 4) for four equally likely turn outcomes.
- For a turtle moving inside a circle centered at the origin, continue while x² + y² <= r² and stop after the position moves beyond r².
- Total distance traveled is the sum of each move's length, while net displacement is the straight-line distance from the origin to the final position.
- TCP provides connection setup, ordered delivery, and retransmission, while UDP sends data without built-in delivery guarantees and has less protocol overhead.
- DNS translates a domain name into an IP address, and caching by browsers, routers, or ISPs can reduce repeated lookup time.
- IPv4 provides 2³² possible address values, while IPv6's 128-bit address space provides 2¹²⁸ possibilities.
Chapters
- Indika Walimuni introduces the drunkard walk as a simplified simulation of a physical process.
- Uniform random numbers make each possible outcome equally likely, unlike Gaussian, Poisson, or Boltzmann distributions.
- The lesson connects simulation to scientific modeling of systems with many interacting particles.
- The turtle moves forward 2 to 5 steps before choosing whether and how to turn.
- Each step is 10 pixels, so a 3-step move at the suggested size covers 30 pixels.
- The first movement begins at the origin, and the exercise uses Python's turtle module.
- The proposed function accepts a step-size parameter and calculates the distance for one movement.
- Python's random.randint(2, 5) selects an inclusive number of steps.
- The function should return the movement distance so a later simulation can accumulate total travel.
- A random integer from 1 through 4 selects among four equally likely actions.
- Choice 1 leaves the turtle's heading unchanged, choice 2 turns left 90 degrees, and choice 3 turns right 90 degrees.
- Choice 4 turns the turtle around by 180 degrees, and a pass statement can represent the no-action branch.
- Part two confines the drunkard to a circle centered at the origin with a specified radius.
- A while loop continues movement until the turtle crosses the boundary.
- The simulation must inspect the turtle's current x and y coordinates to test whether it remains inside the circle.
- For a circle centered at (0, 0), the boundary condition is x² + y² = r².
- The turtle is inside or on the boundary when x² + y² <= r², and outside when x² + y² > r².
- The geometric condition supplies the Boolean test for continuing or ending the while loop.
- Initialize total distance to zero, then add the returned distance from each single-move function call.
- Update the turtle's current position during the loop so the boundary condition reflects each new move.
- Net displacement differs from total distance traveled: displacement is the straight-line distance from the origin to the endpoint.
- Indika tests the turtle movement and turn behavior, including changing the step-size parameter from 10 to 20.
- The lesson then shifts from the simulation exercise to internet protocols, beginning with a comparison of TCP and UDP.
- The circular-boundary solution is left for students to complete from the posted plan.
- TCP, or Transmission Control Protocol, is presented as a way to deliver data reliably and in order.
- The lesson describes a connection-oriented setup using a three-way handshake before data transfer.
- TCP retransmits data when a packet does not arrive, supporting complete web pages and file downloads.
- The lesson traces internet development from military research through later National Science Foundation support and wider public access.
- A packet carries destination information, data, and other fields needed for network communication.
- Routers forward packets toward their destination, and different packets may take different paths through the network.
- Routers select paths for packets and pass them between connected networks and computers.
- IP establishes communication addressing rules, while TCP provides reliable packet delivery in the TCP/IP model.
- An internet service provider, such as AT&T, Xfinity, or Starlink, provides a user's connection to the internet.
- A request from a client typically passes through its ISP before reaching a server such as Amazon.
- The server's response returns as packets and may follow a different route from the original request.
- The lesson notes that ISPs may retain access logs and that disclosure can be subject to legal process.
- An IP address identifies a network destination, while domain names give people a more memorable way to refer to websites.
- IPv4 addresses use 32 bits, commonly written as four decimal groups separated by dots.
- DNS connects domain names to the numeric addresses that browsers use to contact servers.
- A DNS server looks up the IP address associated with a domain such as cnn.com.
- The browser can use the returned address to contact the website's server.
- The lesson compares DNS to a phone book or dictionary that maps names to numeric information.
- A client first sends a DNS lookup request, receives the server's IP address, and then connects to the site.
- Browser, router, and ISP caches can retain DNS results to speed up later access.
- Caching avoids repeating the lookup for every visit to a previously accessed site.
- The number of addresses represented by 32 bits is 2³², approximately 4.3 billion.
- IPv6 uses 128 bits, allowing 2¹²⁸ possible addresses and vastly expanding the address space.
- The lesson contrasts IPv4's dotted-decimal notation with the hexadecimal groups used in IPv6.
- A server generally uses a static IP address so clients can continue reaching it through DNS.
- Client devices commonly receive dynamic IP addresses from their ISP, and the assigned address can change.
- The new Python task asks students to extract a domain name from a full URL after completing the assigned SciBook sections.
Transcript excerpt
0:00 Good morning, guys. This is our agenda today. Um we are going to solve this problem first, the drunkard problem. So let's go to that one. Okay. So this is an interesting problem. Actually, this is a small simulation in fact, okay. So this is what actually pretty much at the core they many like you know scientists, sometimes physics, even chemistry or statisticians, they run simulation based on already established principle. In this case, the principle is given to you like you know
0:46 drunk card move randomly, but only in four directions, not all throughout, right? So that's the simplification actually for this class, okay. And then this could be you know the stock market and you can actually simulate up to some accuracy accuracy the stock market and they say you know past performance, no guarantee future returns, right? But yes, you can still kind of simulate the future behavior of stock market up to some accuracy. Like for example, nowadays like 80%, 90%. So I mean your prediction has a bit of 90% chance. It's it's a good bet, right? So right? So yeah.
1:34 So and then you can so this is such an example, but it's the simplest level to fit this class, okay. So in this case and we are actually simulating a physical phenomenon in this case walk of a random drunk person, okay. So and then actually behavior is naturally naturally random. And we know how to create um very close random numbers to natural random numbers, which is pseudo random numbers encoding, right? So and then this is what actually um like scientists do if they know the distribution of the behavior and then if it is
2:23 kind of in in statistical in nature, right? So so if if if the interaction involve large number
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, indika walimuni.