;;;; srfi.27.geometrics.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.geometrics (;export *make-random-geometrics make-random-geometrics) (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-geometrics (number random-real-function -> number-function)) (: make-random-geometrics (#!rest -> number-function procedure)) ;;; Geometric distribution (define (*make-random-geometrics p randoms) (let ((log-p (log p))) (lambda () (+ 1 (inexact->exact (floor (/ (log (- 1 (randoms))) log-p)))))) ) (define (make-random-geometrics #!key (p 1/2) (randoms (current-random-real))) (check-real-unit 'make-random-geometrics p 'p) (check-procedure 'make-random-geometrics randoms 'randoms) (values (*make-random-geometrics p randoms) (lambda () (values p randoms))) ) ) ;module srfi.27.geometrics