What's the preferred way of generating a random floating-point number in the range of a given floating-point type? We have uniform!T() for integral types, but nothing similar for floats? And uniform(-real.max, real.max) (possibly tweaking the limits) seems to only return inf, which isn't terribly helpful.

What's the standard thing to do here? I could just use

 uniform(cast(T) -1, cast(T) 1)*T.max

I guess (for some floating-point type T). Seems to work fine, at least.

Am I missing the obvious way to do it?

--
Magnus Lie Hetland
http://hetland.org

Reply via email to