;;;; random-source.scm ;;;; Kon Lovett, Oct '09 (module random-source (;export *make-random-source random-source? check-random-source error-random-source *random-source-name *random-source-documentation *random-source-log2-period *random-source-maximum-range *random-source-entropy-source *random-source-entropy-source-set! @random-source-constructor @random-source-state-ref @random-source-state-set! @random-source-randomize! @random-source-pseudo-randomize! @random-source-make-integers @random-source-make-reals ; registered-random-sources registered-random-source unregister-random-source register-random-source!) (import scheme chicken (only data-structures alist-ref alist-update!) (only srfi-1 alist-cons alist-delete!) (only type-checks define-check+error-type check-procedure check-symbol)) (require-library data-structures srfi-1 type-checks) (use registration) ;; (define-record-type random-source (*make-random-source ctor name docu log2-period maxrng es state-ref state-set! randomize! pseudo-randomize! make-integers make-reals) random-source? (ctor @random-source-constructor) (name *random-source-name) (docu *random-source-documentation) (log2-period *random-source-log2-period) (maxrng *random-source-maximum-range) (es *random-source-entropy-source *random-source-entropy-source-set!) (state-ref @random-source-state-ref) (state-set! @random-source-state-set!) (randomize! @random-source-randomize!) (pseudo-randomize! @random-source-pseudo-randomize!) (make-integers @random-source-make-integers) (make-reals @random-source-make-reals) ) (define-check+error-type random-source) ;; Random Source Constructor Registry (define +reg+ (make-registration 'random-source '())) (define (registered-random-sources) ((@registration-key +reg+)) ) (define (registered-random-source name) ((@registration-ref +reg+) name) ) (define (unregister-random-source name) ((@registration-deref! +reg+) name) ) (define (register-random-source! name ctor) ((@registration-register! +reg+) name ctor) ) ) ; module random-source