(define (sample-probability elements probs)
(let* ((total (apply + probs))
(choice (random total)))
(let loop ((els elements)
(probs probs)
(running-sum 0))
(let ((next-sum (+ running-sum (car probs))))
(if (< choice next-sum)
(car els)
(loop (cdr els)
(cdr probs)
next-sum))))))
(define (tabulate N fn )
(let loop ((table '())
Comment too long. Click here to view the full text.