What type of random number engine is used with a given random distribution?

C ++ 11 random number generation method:

  • Instant engine start with numerical numbers
  • Create random distribution
  • Click random numbers from the engine through the distribution

The problem is that both the random number pattern and the random distribution of patterns by the type of arithmetic used.

How to connect these two types of arithmetic?

Can you use a 32-bit integer for the kernel and a 64-bit integer for distribution and vice versa? What is the danger? What about floating point types?

I hypothesize that the number of possible numbers generated by the engine must be greater than or equal to the number of different random numbers that you hope to receive. Unfortunately, I could not test my hypothesis, since on my computer uint_fast32_t and uint_fast64_t same, and therefore both proposed mechanisms for each of the three C ++ 11 generators give the same results.

The documentation for C ++ 11 distributions like std :: uniform_real_distribution or std :: uniform_int_distribution is incomplete in this regard:

This section is incomplete. Reason: generator requirements

But for exappleple, the implementation of gcc 4.7 uniform_real_distribution :

  template<typename _UniformRandomNumberGenerator> result_type operator()(_UniformRandomNumberGenerator& __urng, const param_type& __p) { __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> __aurng(__urng); return (__aurng() * (__p.b() - __p.a())) + __p.a(); } 

Where is the adapter:

An adapter class for converting the output of any Generator into input for a specific distribution.

“any” sounds encouraging, but is that standard? I am particularly concerned about hidden overflows that are difficult to detect and that could jeopardize the correct distribution.

+7
c ++ random c ++ 11
source share
1 answer

You are allowed to use any random number generator (URNG) for any distribution function. It is assumed that the distribution function knows what it needs, and a URNG is required to describe what it provides, so that the distribution function can request sufficient entropy for its needs. (Note that the “engine” is a URNG, with some additional requirements, such as seed-like.)

The "universal" adapter that you mention in the GNU standard library implementation accepts a single random number generator G (in fact, this name is much longer, but it is tedious) and the result type is R , which must be a numeric type. G must determine G::min and G::max , the minimum and maximum values ​​that it can return, and it must return all values ​​between these limits with equal probability. Therefore, it is easy to know how many bits of randomness are available from a call to G() . Moreover, from numeric_limits<R> will tell us how many bits are needed for R Thus, dividing the entropy required by the available entropy tells the adapter how many times it needs to call G to get a uniformly random R Thus, the adapter accepts any URNG / engine that produces some type of result, and adapts it to get a different type of result.

+2
source share

All Articles