isUniformRNG
Joseph Rushton Wakeling via Digitalmars-d
digitalmars-d at puremagic.com
Sun May 4 00:47:06 PDT 2014
On 04/05/14 04:03, Nick Sabalausky via Digitalmars-d wrote:
> In std.random, is the "isUniformRNG" intended to determine whether the given
> type is *some* RNG or just a *specific* form of RNG? Because I don't see any
> "isRNG" that's more general.
Yes, it is meant to denote that the type is a _uniform_ random number generator,
that is, it's an input range whose elements are numbers drawn from a uniform
distribution. One could even be more strict as per the C++11 standard and
specify that it's a range whose elements are unsigned integral types uniformly
distributed in the closed interval [min, max].
Personally speaking, I have spent quite a lot of time being uncertain about
whether the constraint to only unsigned integral types is entirely appropriate
(e.g. Boost::Random contains RNGs whose underlying type is floating-point), but
it _does_ greatly simplify many design factors. For example, the fact that
you're given a guarantee about bounds makes things much simpler when you move on
to (say) random distributions, such as the uniform distribution, where you want
to control precisely the upper and lower bound behaviour (closed or open).
About a more general "isRNG" template: can you be more precise about what you
are interested in achieving with this? Generally speaking I would find it
rather dangerous to go passing around sources of randomness without having some
understanding of their properties :-)
I should also add: the C++11 standard distinguishes between uniform random
number generators (the aforementioned
uniformly-distributed-unsigned-integers-in-[min, max]) and uniform
_distributions_, which take the output of a uniform RNG and transform it into
random values drawn from other distributions. Again, here we can see the
importance of C++11's strict definition of a uniform RNG: suppose we take a
uniform _distribution_ of floating-point numbers in the half-open range [0, 1)
and use it as the _source_ of randomness for a uniform distribution in the
closed interval [0, 1]. It won't work, because the assumptions about bounds
won't work.
> More importantly, should a crypto RNG count as "isUniformRNG"?
If it's producing unsigned integral types uniformly distributed in a closed
interval [min, max], why not?
More information about the Digitalmars-d
mailing list