# Advice on Library Interface

**Andrew J Bromage
**
ajb@spamcop.net

*Thu, 8 May 2003 13:51:33 +1000*

G'day.
On Wed, May 07, 2003 at 11:18:01AM -0400, Matthew Donadio wrote:
>* 1. Should the functions generate the necessary uniforms, or accept a
*>* list of uniforms? In other words, shuld the signature be
*>*
*>* wgn :: Int -- ^ seed to generate the uniforms
*>* -> [Double] -- ^ list of Gaussian random variables
*>*
*>* or
*>*
*>* wgn :: [Double] -- ^ list of uniform random variables
*>* -> [Double] -- ^ list of Gaussian random variables
*
IMO, the first is unacceptable because I may want to plug in my own
random numbers. In addition, I may not want to seed my random number
generator from a simple Int (e.g. if I need cryptographically strong
Gaussian random numbers; no idea why, of course).
OTOH, if you're using the algorithm I'm thinking of, wgn turns two
uniform random numbers into two Gaussian random numbers. The type
declaration above suggests that if I give you an odd number of uniform
random variables, I'll get the same number of Gaussian random variables.
Speaking as someone who uses random numbers regularly, though, what
I want to do is not plug in random numbers, but rather plug in a
random number generator. Something like this perhaps:
class (Monad m) => RNG rng m | rng -> m where
getUniformRand :: rng -> m Double
wgn :: (Monad m, RNG rng m) => rng -> m [Double]
>* 2. Should the functions accept mean and/or variance parameters, or
*>* should they generate unit normals?
*
Is there a reason not to provide both?
Cheers,
Andrew Bromage