Should uniform(-real.max, real.max) be inf?
Magnus Lie Hetland
magnus at hetland.org
Thu Mar 1 02:52:49 PST 2012
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
More information about the Digitalmars-d-learn
mailing list