Computer Science Teacher
Computer Science Teacher - Thoughts and Information from Alfred Thompson

December, 2009

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    Monte Carlo Simulation – Slot Machines


    Random numbers are fun. Really they are. They are at the heart of gambling for sure but they are also a key part of what is called a Monte Carlo Simulation. These simulations are used for all sorts of scientific, financial, engineering and other simulations. They are an attempt to figure the effects of chance, of random reactions, to a formula/algorithm or plan. As such they are an important tool in many fields. But of course Monte Carlo refers to the famous casino so its association with gambling is pretty much unavoidable. This even though the term originated with a group of nuclear researchers that included the computer pioneer John von Neumann. And as it turns out I have a couple of gambling simulations in mind that I think make interesting projects.

    The first was inspired by this slot machine simulator that I found as a result of a Tweet on Twitter.


    It’s pretty fancy and clearly some serious research went into it. Just for fun I decided to create a very simple version of a slot machine simulation. I didn’t do much research so it’s not as scientific but it was fun to do. The form is below and you can see that I used textboxes to allow the user to specify the starting amount, how much to bet on each spin and how many spins to do. The payoff rate I hard coded in but could easily be another variable the user could set. The payoffs is determined by an other random number and could be a lot more fancy. Probably should be.



       1: private void button1_Click(object sender, EventArgs e)
       2:       {
       3:           int bankRoll = Int16.Parse( this.textBox1.Text);
       4:           int bet = Int16.Parse(this.textBox2.Text);
       5:           int cnt = Int16.Parse(this.textBox3.Text);
       6:           Random r = new Random();
       7:           for (int i = 0; i < cnt && bankRoll >= bet; i++)
       8:           {
       9:               if (r.Next(100) > 90)
      10:               {
      11:                   bankRoll += r.Next(100);
      12:               }
      13:               else
      14:                   bankRoll -= bet;
      15:           }
      16:           this.label1.Text = bankRoll.ToString();
      17:       }

    Making this better is an exercise for the student. I hope to write this up in some more detail at a future date but I’m on vacation so it will wait. But there are a couple of things I do like about it. One is that I get to use a more complex terminating clause than we often see in an early student project. It allows for some discussion about the roll of negative numbers in loops. Do you allow them? It depends on the application doesn’t it? Slot machines typically do not grant credit. And of course there are those random numbers to look at so you can get into all sorts of discussions about random numbers, statistics and streaks. Why do you sometimes win? Good stuff.

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    Web Development or Computer Science


    I love to look at the logs to see how people find this blog. Some of the search strings people use amaze me. Sometimes I’m not sure which to wonder more about – how did that string find my blog or what in the world are they really looking for. Recently I saw a search for “is it better to study computer science or web development” that was a bit of a puzzler. I’m not sure those are separate subjects. Can you do good web development without a grounding in computer science? Can you be a knowledgeable computer scientist without some knowledge of web development? Probably not.

    I suspect that at the heart of this question was a vocational idea. What career should they go into? Programming (which is what many people think of when they think of computer science) or web development (which many people don’t seem to be aware requires some computer science to do well).

    These days most important web pages have database access, active response, and other “programming” that take them a whole level beyond the static web pages of the past. It’s hard to see how one can keep up with the trends towards AJAX, HTML5, Silverlight, Cloud computing and so much more of the direction of the web without a good computer science background. Sure there are self taught people who do great things  but having a good solid base of computer science knowledge would seem to be a big edge for learning the new technologies.

    Related to this is that I keep seeing people list HTML as a programming language. That confuses me. I’ve worked with mark up languages for years (anyone else remember Runoff?) and while they are useful tools I see them as data rather than as programming languages. Are they part of computer science? For sure. They take in data, meta data, process descriptions and much more. But HTML is not a programming language. Perhaps this is part of that whole confusion that has people thinking computer science and programming are the same thing? Are people calling HTML a programming language an attempt by people to try to justify calling web development computer science? If so, I think they are missing the point. Web development is a part of computer science.

    It may not have the prestige in academic circles that other parts of CS have but it is growing in importance in the “real world” all the time. I think we really want the people developing the next big web app (think Facebook, Twitter and to know a bit about “the rest” of computer science. What do you think? Is HTML programming? Is web development computer science? Or is it rightly kept separate?

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    Where to Find Computer Science Lectures Online


    With school vacations coming up this seemed like a great time to accept this guest blog post from education writer Karen Schweitzer. I can imagine a lot of people looking for ways to do something educational over the holiday. While many of these may be a bit much for high school students some will be ready for them. Plus they may be helpful for continuing education for high school computer science teachers and for undergraduate students.

    Where to Find Computer Science Lectures Online

    Computer science lectures are a great way to introduce yourself to the world of computer science or expand your current knowledge. Here are hundreds of college-level computer science lectures available for free online.

    Freshman Computer Science Seminar - This free computer science seminar held for college freshmen at UCLA includes ten audio lectures. You can play the lectures with Real Player, download them to an mp3 player, or subscribe through iTunes.

    Understanding Computers and the Internet - Harvard offers an excellent introduction to computer science with a focus on understanding computers and the Internet in this series of 12 lectures. Lectures are available in Flash, QuickTime, and mp3 format and include slides, transcripts, and other learning materials.

    Higher Computing - The introductory course for computer science at the University of New South Wales (UNSW) can be taken for free by watching a series of nearly 50 video lectures on the school's YouTube channel.

    Operating Systems and Systems Programming - UC Berkeley offers this series of free computer science lectures on operating systems and systems programming. Most of the lectures include an audio and video version. Some lectures also include accompanying slides.

    The Structure and Interpretation of Computer Programs - This series of computer science lectures, also from UC Berkeley, includes more than 40 free audio and video lectures on topics like functional programming, object-oriented programming, logic programming, data abstraction, sequences, streams, and concurrency.

    Programming Languages - The University of Washington provides a series of free audio and video lectures on computer programming. Lectures include PowerPoint and PDF slides and can be played with Windows Media Player or downloaded to your computer or mp3 player.

    Programming Methodology - Professor Mehran Sahami for the Stanford University Computer Science Department delivers a series of free computer science lectures through Stanford's YouTube channel. Each lecture lasts 40 to 50 minutes.

    Multicore Programming Primer - The Massachusetts Institute of Technology (MIT) offers a series of video lectures that use the Playstation 3 platform to teach computer science majors about parallel programming and multicore architectures. The lectures include accompanying notes, a set of recitations, and quizzes with solutions.

    Introduction to Computer Architecture - Prof. Anshul Kumar, Department of Computer Science & Engineering, IIT Delhi delivers a series of six video lectures on the basics of computer architecture through YouTube.

    Computer Systems Engineering - This series of free computer science lectures, also from MIT, consists of more than 20 video lectures on computer software and hardware systems engineering. Lectures are accompanied by other learning materials, including lecture notes, assignments, and exams with solutions.

    Guest post from education writer Karen Schweitzer. Karen is the Guide to Business School. She also writes about online degree programs for

Page 1 of 7 (20 items) 12345»