; o tannenbaum
; rand -- returns integer on range 0 .. 2^32-1
(define rand ; marsaglia linear congruential method
(let* ((a 69069) (c 1234567) (m 4294967296)) ; due to knuth
(lambda () (set! seed (modulo (+ (* a seed) c) m)) seed)))
; seed -- number of seconds since the Unix epoch NON-PORTABLE
; please report ports to other Scheme systems to the author
; uncomment exactly one of the next four options
; (define seed (time-second (current-time))) ; chez
(define seed (current-seconds)) ; racket/chicken
; (define seed (current-time)) ; guile
; (define seed (inexact->exact (round
; (time->seconds (current-time))))) ; gambit
(define (center width str)
(let* ((len (string-length str))
(indent (quotient (- width len) 2)))
(display (make-string indent #\space))
(display str) (newline)))
(define (row n)
(let loop ((n n) (str ""))
(if (zero? n) str
(loop (- n 1)
(string-append
(if (< (rand) 536870912) "*" "O")
" " str)))))
(define (tannenbaum)
(center 60 "*")
(do ((n 2 (+ n 1))) ((< 20 n))
(center 60 (row n)))
(do ((n 1 (+ n 1))) ((< 3 n))
(center 60 "XXX")))
(tannenbaum)