---
title: Eboard 12  Randomness
number: 12
section: eboards
held: 2019-02-20
link: true
---
CSC 151 2019S, Class 12:  Randomness
====================================

_Overview_

* Preliminaries
    * Notes and news
    * Upcoming work
    * Extra credit
    * Questions
* Lab
* Discussion

Preliminaries
-------------

### News / Etc.

* I brought donut-like substances for my 207 class and there are leftovers.
  They are fair game.
* Mentor sessions Wednesday (TONIGHT) 8-9 p.m., Thursday 8-9 p.m., 
  Sunday 5-6 p.m.
* If you have not done so already, please sign and return the
  [class code of conduct](../handouts/code-of-conduct).
* Remember: Book office hours at <https://rebelsky.as.me/schedule.php>
* Remember: I do take questions via email, and writing up questions can
  often help you think through a problem.
* You should be getting an email about the CPUS.  Let me know if you have
  questions.

### Upcoming work

* Reading due before class Friday
    * [Local bindings](readings/local-bindings)
    * Once again, this won't be ready until this evening.
* [Exam 1](../exams/exam01) epilogue due **Tonight**.
* [Assignment 5](../assignments/assignment05) due next Tuesday.
    * Not yet posted; should appear tonight.  (Maybe sooner.)
    * Your homework partner is your partner for today's class.
    * Theme: Write programs that generate "interesting" texts
      (a better extension of the `sentence` example for the reading).
* [Flash cards](../flashcards/flashcards05) due **Tonight** at 8:00 p.m.
    * Covers Wednesday/Friday/Monday classes
* Quiz Friday: Conditionals, Preconditions and Postconditions,
  Precondition checking, and Testing.
    * Sample quizzes forthcoming.
* [Lab writeup](../labs/writeup12) due before class Friday
    * Exercises: 9a and 9b
    * Subject: CSC 151.01 Writeup for Class 12 (YOUR NAMES) 
    * To: csc151-01-grader@grinnell.edu

### Extra Credit

#### Extra credit (Academic/Artistic)

* CS Extras, Thursday, 4:15 p.m. Science 3821: Sam talks about course design.
  (Snacks at 4pm in the CS Commons.)
* Iowa Flautists in Concert.  Saturday, 23 February 2019.
  3:45 p.m. Sebring-Lewis Hall.

#### Extra credit (Peer)

* Grinnell Symphony, Wednesday, 7:30 p.m., in Sebring-Lewis
* Men's BBall, Friday, 3:00 p.m. vs. LFC at St. Norbert.  (Hopefuly a
  Saturday game, too.)
* Indoor Track and Field, Friday and Saturday, at Monmouth.

#### Extra credit (Wellness)

* 30 Minutes of Mindfulness at SHACS every Monday 4:15-4:45
* Any organized exercise.  (See previous eboards for a list.)
* 60 minutes of some solitary self-care activities that are unrelated to 
  academics or work.  Examples include "read for pleasure" or "take a
  walk" or "make snow angels" or take a necesssary nap.  Your email 
  reflection must explain how the activity contributed to your wellness.
* 60 minutes of some shared self-care activity with friends, such as 
  making a meal, having a snowball fight, or playing a board game.
  Your email reflection must explain how the activity contributed to
  your wellness.

#### Extra credit (Misc)

### Other good things 

### Questions

What's the `let` thing in the reading?

> It should not have been there.  I've removed it.

How does `roll-dice` work?

> It uses a technique (recursion) that we won't learn for two weeks.  Pay 
  attention to the *what* not the *how*.

Lab
---

I don't know if it's comforting or not, but I watched some very smart
students in my CSC 207 class inserting the same subtle error that occurs
in `play-seven-eleven`.

If you're not sure how to fix the error in `play-seven-eleven`, consider
(a) writing a procedure `(seven-or-eleven? val)` that determines whether
val is seven or eleven or (b) use `disjoin` and `section` to build a
procedure that does the same.

Lab writeup: 9a, 9b

Discussion
----------

What are the odds for winning seven-eleven? 

> 8/36 = 0.222222222222

What are the odds of winning the badly designed seven-eleven?

> 6/36 + 30/36*2/36 = 0.21296296296296297

How would Sam fix `play-seven-eleven`?

        (define seven-or-eleven?
          (lambda (x)
            (or (= x 7) (= x 11))))

        (define play-seven-eleven
          (lambda ()
            (if (seven-or-eleven? (pair-a-dice))
                1
                0)))

Important!  When possible, *call* another procedure, rather than
*copy* the body.

_Good_

        (define ignore-then-roll
          (lambda (x)
            (roll-a-die)))

        (define random-student
          (lambda ()
            (random-element students)))

_Bad_

        (define ignore-then-roll
          (lambda (x)
            (+ 1 (random 6))))

        (define random-student
          (lambda ()
            (list-ref students (random (length students)))))
