2015-11-12 LabRandom + HW

posted Nov 12, 2015, 4:51 AM by Samuel Konstantinovich   [ updated Nov 12, 2015, 5:41 AM ]
    0. Complete the lab! (this is assumed)
    1. Submit Hanoi + The newest Fib lab on the new HW server slot. Comment out your test cases but don't remove them. The deadline is tonight, since all you have to do is copy/paste into a text file.
    2. On a computer make an racket file with interesting list of :
        - singular nouns 
        - verbs  (runs, walks, talks ... etc)
        - adjectives
        (at least 20 interesting words of each category)
    3. Name the lists as follows so that we can refer to them later:
    4. You need this file in class tomorrow!

Goal: Random stuff...
Do now on the computer:

Consider that we index elements of a list starting at 0:
  0th 1st  2nd   3rd 
'(the best thing ever)
So the value at index 1 is "best"

Write a function (getNth L n) which takes a list L and returns the n'th top level element of the list.
You may assume that n >= 0, and n < the number of top level elements of the list.

(getNth '(5 9 10 4 3) 0) returns 5
(getNth '(5 9 10 4 3) 1) returns 9
(getNth '(5 9 10 4 3) 2) returns 10

When you are done try the following:
1. Switch your racket language to 'Pretty Big'
2. Test the (random x) command. And on paper:
   a) What does x have to be for this command to work?
   b) can random take more than 1 argument?
   c) With respect to x what is the range of possible values?
   d) How can this command be useful when writing programs?

3. Now that you have that completed, write a function:
(getRandomElement L) that returns one of the top level elements of the list. It should be able to give you any of the elements, including the last. 

Read + Answer in your notes before you write any code: 
-You have worked on a do now that is relevant to your work right now. 
1) You need to test your code with your own test cases, What will you test with and what should happen?
2) What is the range of indices of the list that we want to generate in our function?
2) How might we use this particular function? Write down 3 creative/interesting/fun programs you might be able to write using this function.

Test your function on different sized lists and make sure that it works after running the command many times. (Smaller lists are easy to test)

4. Where are we going with this?!?!? Check out the homework