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.
c ++ random c ++ 11
Martin Drozdik
source share