source: project/release/4/srfi-27/trunk/srfi-27-poissons.scm @ 35456

Last change on this file since 35456 was 35456, checked in by Kon Lovett, 17 months ago

begin typing, dep /

File size: 1.1 KB
Line 
1;;;; srfi-27-poissons.scm
2;;;; Kon Lovett, Dec '17
3;;;; Kon Lovett, Jun '17
4;;;; Kon Lovett, May '06
5
6; Chicken Generic Arithmetic! (could use fp routines)
7
8(module srfi-27-poissons
9
10(;export
11  *make-random-poissons
12  make-random-poissons)
13
14(import scheme chicken)
15
16(use
17  (only type-errors error-argument-type)
18  (only type-checks
19    define-check+error-type
20    check-procedure
21    check-cardinal-integer
22    check-real
23    check-open-interval
24    check-closed-interval)
25  srfi-27
26  srfi-27-distributions-support)
27
28;;; Poisson distribution
29
30(define (*make-random-poissons mu randoms)
31  (let ((emu (exp (- mu))))
32    (lambda ()
33      ;FIXME O(mu) but O(log(mu)) desired for >> mu
34      (do ((m 0 (fx+ 1 m))
35           (prod (randoms) (* prod (randoms))))
36          ((<= prod emu) m)))) )
37
38(define (make-random-poissons #!key (mu 1.0) (randoms (current-random-real)))
39  (check-nonnegative-real 'make-random-poissons mu 'mu)
40  (check-procedure 'make-random-poissons randoms 'randoms)
41  (values
42    (*make-random-poissons mu randoms)
43    (lambda () (values mu randoms))) )
44
45) ;module srfi-27-poissons
Note: See TracBrowser for help on using the repository browser.