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

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

begin typing, dep /

File size: 1023 bytes
Line 
1;;;; srfi-27-bernoullis.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-bernoullis
9
10(;export
11  *make-random-bernoullis
12  make-random-bernoullis)
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;;; Bernoulli distribution
29
30(define (*make-random-bernoullis p randoms)
31  (cond
32    ((= 0.0 p) (lambda () #f))
33    ((= 1.0 p) (lambda () #t))
34    (else      (lambda () (<= (randoms) p)))) )
35
36(define (make-random-bernoullis #!key (p 0.5) (randoms (current-random-real)))
37  (check-real-unit 'make-random-bernoullis p 'p)
38  (check-procedure 'make-random-bernoullis randoms 'randoms)
39  (values
40    (*make-random-bernoullis p randoms)
41    (lambda () (values p randoms))) )
42
43) ;module srfi-27-bernoullis
Note: See TracBrowser for help on using the repository browser.