Implementation of make-random-real-generator Bradley Lucier (05 May 2020 01:07 UTC)
Re: Implementation of make-random-real-generator John Cowan (05 May 2020 03:02 UTC)
Re: Implementation of make-random-real-generator Lucier, Bradley J (05 May 2020 03:30 UTC)
Re: Implementation of make-random-real-generator John Cowan (05 May 2020 04:11 UTC)
Re: Implementation of make-random-real-generator Arvydas Silanskas (05 May 2020 18:49 UTC)
Re: Implementation of make-random-real-generator Marc Nieper-Wißkirchen (05 May 2020 19:00 UTC)
Re: Implementation of make-random-real-generator Bradley Lucier (05 May 2020 19:08 UTC)
Re: Implementation of make-random-real-generator John Cowan (05 May 2020 20:25 UTC)
Re: Implementation of make-random-real-generator Lucier, Bradley J (05 May 2020 20:27 UTC)
Re: Implementation of make-random-real-generator Shiro Kawai (05 May 2020 20:32 UTC)
Re: Implementation of make-random-real-generator Marc Nieper-Wißkirchen (05 May 2020 20:38 UTC)
Re: Implementation of make-random-real-generator Shiro Kawai (05 May 2020 20:55 UTC)
Re: Implementation of make-random-real-generator Bradley Lucier (05 May 2020 20:58 UTC)
Re: Implementation of make-random-real-generator John Cowan (05 May 2020 21:01 UTC)
Re: Implementation of make-random-real-generator Marc Nieper-Wißkirchen (05 May 2020 21:07 UTC)
Re: Implementation of make-random-real-generator Shiro Kawai (05 May 2020 21:01 UTC)
Re: Implementation of make-random-real-generator Bradley Lucier (05 May 2020 20:57 UTC)

Implementation of make-random-real-generator Bradley Lucier 05 May 2020 01:07 UTC

make-random-real-generator is defined as

(define make-random-real-generator
   (case-lambda
     ((low-bound up-bound)
      (make-random-real-generator default-random-source low-bound up-bound))
     ((rand-src low-bound up-bound)
      (let* ((rand-int-proc (random-source-make-integers rand-src))
             (steps (expt 2 32))
             (rand-real-proc (lambda ()
                               (/ (inexact (rand-int-proc steps))
                                  (- steps 1))))
             (range (- up-bound low-bound)))
       (lambda ()
         (+ low-bound (* (rand-real-proc) range)))))))

I'm curious, if you're basing this SRFI on SRFI 27, why you decided to
build your own rand-real-proc based on randomly generated integers
rather than simply use random-real from SRFI 27.

For implementations with unboxed 64-bit IEEE floating-point arithmetic,
the fundamental generator for SRFI 27 is most likely written using
floating-point, and returns a float strictly between 0 and 1.

Since in many implementations SRFI 27's random-real would be faster and
would serve (almost) as good a purpose as the current implementation, I
recommend using it here.

Brad

Some secondary issues:

It's true that random-real can take slightly fewer than (expt 2 32)
possible values, while your generator can tabut that doesn't seem to be
an issue here.

A secondary issue is that the expression for rand-real-proc mixes
inexact and exact arithmetic, which can lead to run-time slowdowns.