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)

Re: Implementation of make-random-real-generator Bradley Lucier 05 May 2020 19:08 UTC

On 5/5/20 2:48 PM, Arvydas Silanskas wrote:
>>  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
>
> The only reason is because it was defined for the generator to return
> lower and upper bounds inclusively,

Meeting the spec is a great reason!

But as Marc pointed out, sampling from (a,b) (exclusive) is the same as
sampling from [a,b] (inclusive), because the probability of choosing a
or b is 0.

So I recommend using random-real to get a random float between 0 and 1
(exclusive, as it is implemented).

It could still happen, however, that the expression

(+ a (* (- b a) (random-real)))

could return a or b because of rounding, e.g., if

a = 1e15
b = 1e15 + 1.

then 1e15 + (random-real) could return either 1e15 (if (random-real) is
close enough to 0) or 1e15+1. (if (random-real) is close enough to 1).

So documenting the possibility of returning a or b is a good thing, but
the implementation should just use SRFI 27's built in (random-real).

Brad