Re: Consolidated response before finalization
Bradley Lucier 10 Jul 2020 20:33 UTC
On 7/10/20 2:29 PM, Bradley Lucier wrote:
>
> ;;; define N servers with exponentially distributed service
> ;;; times with given mean.
>
> (define (make-servers N mean)
> (let ((result (make-vector N)))
> (do ((i 0 (fx+ i 1)))
> ((fx= i N) result)
> (vector-set! result
> i
> (with-random-source (sources)
> (make-exponential-generator
> mean))))))
>
> (define servers (make-servers 5 1.0))
>
> (pretty-print (vector-map (lambda (arg) (arg)) servers))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> I expected that servers would be a vector of generators, each associated
> with my carefully controlled random source (and perhaps each with its
> own mean, but not in this example), that I could call when needed.
>
> But it appears that the macro with-random-source actually calls the
> generator once, so servers is a vector of reals.
It appears I need instead
(define (make-servers N mean)
(let ((result (make-vector N)))
(do ((i 0 (fx+ i 1)))
((fx= i N) result)
(vector-set! result
i
(with-random-source (sources)
make-exponential-generator mean)))))
So I think that there need be only
(define (random-source-generator i)
(let ((j 0))
(lambda ()
(let ((new-source (make-random-source))) ;; deterministic
(random-source-pseudo-randomize! new-source i j)
(set! j (+ j 1))
new-source))))
Brad