next up previous contents index
Next: Forming Subsets and Up: More on Generating Previous: Generating Random Data

Generating Systematic Data

We have already used the functions iseq and rseq to generate equally spaced sequences of integers and real numbers. The function repeat   is useful for generating sequences with a particular pattern. The general form of a call to repeat is

(repeat list pattern)
pattern must be either a single number or a list of numbers of the same length as list. If pattern is a single number then repeat simply repeats list pattern times. For example
> (repeat (list 1 2 3) 2)
(1 2 3 1 2 3)
If pattern is a list then each element of list is repeated the number of times indicated by the corresponding element of pattern. For example
> (repeat (list 1 2 3) (list 3 2 1))
(1 1 1 2 2 3)
In Section 6.2 below I generate the variables density and variety by typing them in directly. Using the repeat function we could have generated them like this:
(def density (repeat (repeat (list 1 2 3 4) (list 3 3 3 3)) 3))
(def variety (repeat (list 1 2 3) (list 12 12 12)))



Luke Tierney
Tue Jan 21 15:04:48 CST 1997