Extended Exercise: Creating Lists, Testing Functions

We often encounter situations where we would like to create lists of data that involve namers. For example, we may wish to create large lists of numbers to test a function like <#62649#><#12790#>extract1<#12790#><#62649#> in section~#seclistinlist#12791> on large lists instead of hand-coded small ones. Sometimes we would like to visualize randomly picked data. We can create such functions using recursion on natural numbers and a random number generator.
<#12795#>Exercise 11.3.1<#12795#> Scheme provides the operation <#62650#><#12798#>random<#12798#><#62650#>. It consumes a natural number, <#62651#><#12799#>n<#12799#><#62651#>, and produces a random integer between <#62652#><#12800#>0<#12800#><#62652#> and <#62653#><#12801#>n<#12801#>\ <#12802#>-<#12802#>\ <#12803#>1<#12803#><#62653#>:
<#70999#>;; <#62654#><#12808#>random<#12808#> <#12809#>:<#12809#> <#12810#>N<#12810#> <#12811#><#12811#><#12812#>-;SPMgt;<#12812#><#12813#><#12813#> <#12814#>N<#12814#><#62654#><#70999#>
<#71000#>;; to compute a natural number between <#62655#><#12815#>0<#12815#><#62655#> and <#62656#><#12816#>n-1<#12816#><#62656#><#71000#> 
<#12817#>(define<#12817#> <#12818#>(random<#12818#> <#12819#>n<#12819#> <#12820#>m)<#12820#> <#12821#>...)<#12821#> 
Two successive uses of <#62657#><#12825#>(random<#12825#>\ <#12826#>n)<#12826#><#62657#> may produce two distinct results. Now consider the following definition:
<#71001#>;; <#62658#><#12831#>random-n-m<#12831#> <#12832#>:<#12832#> <#12833#>integer<#12833#> <#12834#>integer<#12834#> <#12835#><#12835#><#12836#>-;SPMgt;<#12836#><#12837#><#12837#> <#12838#>integer<#12838#><#62658#><#71001#>
<#12839#>;; ...<#12839#> 
<#12840#>;; Assume: n ;SPMlt; m<#12840#> 
<#12841#>(d<#12841#><#12842#>efine<#12842#> <#12843#>(random-n-m<#12843#> <#12844#>n<#12844#> <#12845#>m)<#12845#> 
  <#12846#>(+<#12846#> <#12847#>(random<#12847#> <#12848#>(-<#12848#> <#12849#>m<#12849#> <#12850#>n))<#12850#> <#12851#>n))<#12851#> 
Formulate a succinct and precise purpose statement for <#62659#><#12855#>random-n-m<#12855#><#62659#>. Use a number line with an interval to explain the result of <#62660#><#12856#>(random<#12856#><#12857#> <#12857#><#12858#>n)<#12858#><#62660#>. Use a symbolic evaluation to support your explanation.~ external Solution<#62661#><#62661#> <#12864#>Exercise 11.3.2<#12864#> Develop the function <#62662#><#12866#>tie-dyed<#12866#><#62662#>. It consumes a natural number and produces a list of integers. Each of these integers should be between <#62663#><#12867#>-20<#12867#><#62663#> and <#62664#><#12868#>120<#12868#><#62664#>. Use <#62665#><#12869#>tie-dyed<#12869#><#62665#> to test <#62666#><#12870#>draw-circles<#12870#><#62666#> from exercise~#exdrawlistshapes#12871>.~ external Solution<#62667#><#62667#> <#12877#>Exercise 11.3.3<#12877#> Develop the function <#62668#><#12879#>create-temps<#12879#><#62668#>. It consumes a natural number <#62669#><#12880#>n<#12880#><#62669#> and two integers, called <#62670#><#12881#>low<#12881#><#62670#> and <#62671#><#12882#>high<#12882#><#62671#>. It produces a list of <#62672#><#12883#>n<#12883#><#62672#> integers that are between <#62673#><#12884#>low<#12884#><#62673#> and <#62674#><#12885#>high<#12885#><#62674#>. Use <#62675#><#12886#>create-temps<#12886#><#62675#> to test <#62676#><#12887#>check-range<#12887#><#62676#> from exercise~#excheckrange1#12888>. Finally, discuss the following questions. Can we simply feed the result of <#62677#><#12889#>create-temps<#12889#><#62677#> into <#62678#><#12890#>check-range<#12890#><#62678#> or do we need to know the list that <#62679#><#12891#>create-temps<#12891#><#62679#> produced? Are there values for <#62680#><#12892#>low<#12892#><#62680#> and <#62681#><#12893#>high<#12893#><#62681#> such that we don't need to know the result of <#62682#><#12894#>create-temps<#12894#><#62682#> and yet we can predict the result of the test? Which function tests which? What does this tell us about testing with automatically generated test data?~ external Solution<#62683#><#62683#> <#12900#>Exercise 11.3.4<#12900#> Develop the function <#62684#><#12902#>create-prices<#12902#><#62684#>, which consumes a natural number and produces a list with a corresponding of prices between $.10 and $10.00 with increments of a dime. Use <#62685#><#12903#>create-prices<#12903#><#62685#> to test <#62686#><#12904#>dollar-store?<#12904#><#62686#> from exercise~#exdollarstore#12905>. <#12906#>Hint:<#12906#> How many dimes are there between $.10 and $10.00?~ external Solution<#62687#><#62687#> <#12912#>Exercise 11.3.5<#12912#> Develop a program that visualizes a student riot. In preparation of a student riot, a small group of students meets to make paint-filled balloons. The typical riot uses <#62688#><#12914#>RED<#12914#><#62688#> only. Then, on the evening of the riot, the students enter a university's progressive theater with the balloons and throw them all over the seats. The program's only input should be a natural number, which represents the number of balloons thrown. The visualization should use a canvas that contains a black grid and the positions of the balls: rawhtml21 Assume a random distribution of the balls over the theater's seats. Each box in the grid represents a seat. Configure the program so the change of one variable definition changes the number of columns in the grid and a change to another changes the number of rows. <#12915#>Hint:<#12915#> Develop auxiliary functions that draw some given number of lines in the vertical and the horizontal direction.~ external Solution<#62689#><#62689#>