;;;; srfi.27.exponentials.scm ;;;; Kon Lovett, Dec '17 ;;;; Kon Lovett, Jun '17 ;;;; Kon Lovett, May '06 ; Chicken Generic Arithmetic! (would use fp routines, except for the "real" constraint) (module srfi.27.exponentials (;export *make-random-exponentials make-random-exponentials) (import scheme (chicken base) (chicken type) (only (type-checks-numbers scheme) check-real) (only type-checks-structured check-procedure) (srfi 27) srfi-27-distributions-support) ;;; (include-relative "srfi-27-common-types") (: *make-random-exponentials (number random-real-function -> number-function)) (: make-random-exponentials (#!rest -> number-function procedure)) ;;; Exponential distribution ;; Knuth's "The Art of Computer Programming", Vol. II, 2nd ed., ;; Section 3.4.1.D. (define (*make-random-exponentials mu randoms) (if (= 1 mu) (lambda () (- (log (randoms)))) (lambda () (* mu (- (log (randoms)))))) ) (define (make-random-exponentials #!key (mu 1) (randoms (current-random-real))) (check-real-unit 'make-random-exponentials mu 'mu) (check-procedure 'make-random-exponentials randoms 'randoms) (values (*make-random-exponentials mu randoms) (lambda () (values mu randoms))) ) ) ;module srfi.27.exponentials