[CM] small contribution to Op.2, No. 5: Chance and Probability

Terrence Brannon terry@hcoop.net
Wed, 06 Oct 2004 04:54:08 -0400


When I saw this expression:

	(chance? .75)

I got very curious and decided to see how close the percentage of true values 
would be to 75% based on the number of trials I ran, so I wrote this 
Scheme-specific code to check it out:

(use-modules (srfi srfi-1))

(define (percent success trials)
   (* 100
      (/ success trials)))

(define *chance* 0.75)

(define (try-chance trials chance)
   (let* ((dummy-list   (make-list trials))
          (trial-result (loop for tmp in dummy-list collect (chance? chance))))
     (percent (count (lambda (x) x) trial-result)
              trials)))

(define (trial-stats)
   (let* ((powers-of-2 (iota 16 0 1)))
     (loop for power in powers-of-2 collect (try-chance (expt 2 power)
                                                             *chance*))))

(trial-stats)


==
some of the early experimental results are right on the theoretical, but some 
are way off. only after many trials do we consistently get the experimental and 
theoretical close, as we expected.

well, I had some fun with this :)

-- 
Terrence Brannon, terry@hcoop.net