data-generators thoughts added by certainty on Sun Jun 2 14:47:51 2013
#;277> ;; Sequence of characters: #;277> (show (gen-char)) (#\nul #\backspace #\newline #\x5 #\tab) #;278> #;278> ;; Sequence of characters in a given range: #;278> (show (restrict (gen-char) (between #\a #\z))) (#\a #\j #\c #\t #\p) #;279> #;279> ;; Sequence of characters in a given range, where each character is choosen to be the successor of the previously generated #;279> (show (choose (restrict (gen-char) (between #\a #\z)) sequentially)) (#\a #\b #\c #\d #\e) #;280> #;280> ;; The same works for compound generators #;280> #;280> ;; Sequence of lists of fixnums #;280> (show (gen-list (gen-fixnum))) ((0) (1 5 5 6 3) (6 2) (7 10 4 7) (1 9 8)) #;281> #;281> ;; Sequence of lists of fixnums where each list has a random length between 0 and 5 #;281> (show (restrict (gen-list (gen-fixnum)) (between 0 5))) ((0 6 7) () () (4 9 7) ()) #;282> #;282> ;; Sequence of lists of fixnums where each list has a length that is one more than the length of the list that was generated before #;282> ;; upto a length of 5 #;282> (show (choose (restrict (gen-list (gen-fixnum)) (between 0 5)) sequentially)) ((0) (5 5) (2 0 9) (9 4 0 6) (1 10 10 9 1)) #;283> #;283> ;; And finally all together #;283> (show (choose (restrict (gen-list (choose (restrict (gen-char) (between #\a #\z)) uniformly)) (at-most 5)) sequentially)) ((#\a) (#\t #\y) (#\f #\x #\l) (#\v #\p #\x #\x) (#\r #\k #\t #\i #\y)) #;284> #;284> ;; This way you can compose your generators #;284> (define lower-char-gen (restrict (gen-char) (between #\a #\z))) #;285> ;; #;285> ;; Now pick uniformly from them #;285> (show (choose lower-char-gen uniformly)) (#\a #\c #\k #\i #\i) #;286> ;; #;286> ;; Or sequentially #;286> (show (choose lower-char-gen sequentially)) (#\a #\b #\c #\d #\e)