Reminder

  • If you haven't done so already, please fill out the COS 126 student survey. It will only take a minute. Otherwise your name will not get entered in our database, and you will not receive a grade in this course.

  • Goals

  • The goal of this week's assignment is to introduce you to the C programming language and make sure that you can:

  • Read data from standard input and write to standard output - scanf() and printf().

  • Use loops - for and while.

  • Use branches - if and else.
  • Curious students should find it interesting to fully understand why Floyd's method works, and appreciate its elegance. Think on your own about other ways to compute the cycle length, and consider the amount of time and memory used by these methods. (For those of you on the job market, computing the cycle length is a classic Microsoft interview question.)


  • OS Tip of the Week

    We provide sample data files that help you test your program. They are available from our ftp server. Here, you will also find the source code of the programs we use in lecture. For each assignment, you'll probably want to copy the appropriate files to an empty directory on your system. There are a number of ways to copy the files depending on your system.

  • Use your browser. For example, from IE 6.0, go to the ftp server, right click on the folder cycle, and select "Copy to Folder".

  • Use an ftp application. Enter ftp.cs.princeton.edu as the desired site. Use the username anonymous and enter your email address for your password.

  • From Unix, you can do this from the command line with a command like the following:
    scp -r userid@arizona.princeton.edu:/u/cs126/files/cycle .
    
    On arizona, you can shorten it to
    cp -r /u/cs126/files/cycle .
    

  • Testing

  • If you are struggling, here are some hints on getting started. If you aren't experiencing problems, then there's no need to look.

  • To test your code, run your program with the various parameters used in the assignment or you can use the values in these text files. Also, you should run your program on different parameters of your own choosing.

  • You can check your work by comparing your results with our reference programs: trace126-sparc and cycle126-sparc for arizona; trace126.exe and cycle126.exe for Windows. The executables are available via ftp://ftp.cs.princeton.edu/pub/cs126/cycle.

  • Submission

  • Submit the following files using the submission system from the course web page: trace.c, cycle.c, and readme.txt. Don't forget to hit the Run Script button after you've sumbmitted all of your files.

  • Be sure that you do the following in your readme.txt file:

  • Write your name, login, and precept number.

  • Write which operating system, C compiler, and editor you used.

  • List whatever help (if any) that you received.

  • Describe any serious problems you encountered.

  • Do not exceed 80 characters per line.
  • Here is a readme file template to get you started.


  • Enrichment Links

  • If you need pseudo-random numbers in real scientific applications, we recommend the Mersenne Twister. For cryptographic applications, use only pseudo-random numbers that are cryptographically secure such as Yarrow.

  • What happens when the casino screws up the pseudo-random number generator in an electronic game? Computer analyst wins $600,000.



  • Kevin Wayne