Boost.Random Support
#include <boost/int256/random.hpp>
Including this header specializes the traits that Boost.Random uses to reason about integer types, so that uint256 and int256 can be used directly with the Boost.Random engines and distributions such as boost::random::uniform_int_distribution.
This header requires Boost.Random to be available, and is therefore not included by the umbrella header.
The following specializations are provided in namespace boost::random::traits for both uint256 and int256:
| Trait | Purpose |
|---|---|
|
Reports both types as integral. |
|
Reports |
|
Provide the unsigned type mapping Boost.Random uses when generating values ( |
|
Provide the unsigned-or-unbounded type mapping Boost.Random uses (likewise |
These specializations live in boost::random::traits, not boost::int256. The header itself includes nothing from Boost: it forward declares the trait templates, so it costs nothing when Boost.Random is not in use.
|
Because is_signed<int256> is true, boost::random::uniform_int_distribution<int256>{lo, hi} accepts a negative lo and draws over the full signed range, including a distribution spanning (std::numeric_limits<int256>::min)() to (std::numeric_limits<int256>::max)().
An example combining Boost.Random with the library type is available on the examples page.