[mercury-users] a typeclassful random.m

Ralph Becket rafe at csse.unimelb.edu.au
Mon Feb 19 15:17:37 AEDT 2007


Richard A. O'Keefe, Monday, 19 February 2007:
> Two points strike me, both of which tend to imply that a good
> random generator really ought to be part of the library.

What would satisfy most people here would be to add a type class to the
Mercury library specifying the RNG interface and some number of
instances thereof.  The fine details of the interface are to be worked
out, but this discussion has finally prompted us to look at the problem
again.

> (1) I have often wanted a stream of random integers between some
>     lower and upper bounds of MY choice.  A stream of random integers
>     between some implementation-defined lower and upper bounds is far
>     less use.

We are considering requiring that instances of the rng type class
compute a complete machine word of random bits on each call.

>     BUT mapping from implementation-defined bounds to application-
>     specific bounds in a way that preserves equidistribution is far
>     from trivial.

The library module would presumably supply utility predicates to this
end.

> (2) If you want to generate random bit patterns, something that generates
>     the integers 0..2**k-1 for some k is rather convenient.
> 
>     However, there are quite a few applications of random floating point    
>     numbers where returning 0.0 would be a devastating bug.  It took me
>     ages to get my head around this.  I even patched a copy of the
>     Mersenne Twister code to "fix" what I thought was the "bug" of not
>     returning 0.0.  Until the day I happened to have one of those uses
>     where 0.0 really won't do, and I was Enlightened.  (Oh.  Other people
>     really are smarter than me.)

If you've got a [0.0, 1.0) RNG, can't you turn that into a (0.0, 1.0]
RNG by simply subtracting each result of the former from 1.0?

By the way, I'm curious: what sort of problems abhor a 0.0?

-- Ralph
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list