I do not have your random library installed, so I cannot really test what I
have just written, but I would do something like this:
type
RandomVar[A] = proc(rng: var RNG): A
proc uniform(rng: var RNG; a,b: float) : float =
a + (b - a) * rng.random()
proc c(rng: var RNG) : int = 3
proc u(rng: var RNG) : float = rng.uniform(2,18)
proc d(rng: var RNG) : int = rng.randomChoise([1,2,3])
when isMainModule:
var rng = initMersenneTwister(urandom(16))
echo(c is RandomVar[int]) # true
echo(u is RandomVar[float]) # true
echo(d is RandomVar[int]) # true
echo rng.c
echo rng.u
echo rng.d
I think it's much more flexible, because now you can compose with arbitrary
functions, and you do not need to create new types for each typo of composition.