source: project/release/4/srfi-27/trunk/srfi-27-exponentials.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-exponentials.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-exponentials
9
10(;export
11  *make-random-exponentials
12  make-random-exponentials)
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;;; Exponential distribution
29
30;; Knuth's "The Art of Computer Programming", Vol. II, 2nd ed.,
31;; Section 3.4.1.D.
32
33(define (*make-random-exponentials mu randoms)
34  (if (= 1.0 mu)
35    (lambda () (- (log (randoms))))
36    (lambda () (* mu (- (log (randoms)))))) )
37
38(define (make-random-exponentials #!key (mu 1.0) (randoms (current-random-real)))
39  (check-real-unit 'make-random-exponentials mu 'mu)
40  (check-procedure 'make-random-exponentials randoms 'randoms)
41  (values
42    (*make-random-exponentials mu randoms)
43    (lambda () (values mu randoms))) )
44
45) ;module srfi-27-exponentials
Note: See TracBrowser for help on using the repository browser.