/////////////////////////////////////////////////////////////////// // Copyright Christopher Kormanyos 2018 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // /////////////////////////////////////////////////////////////////// #include #include #include #include #include namespace local_random { template auto generate() -> bool { using random_engine_type = std::mersenne_twister_engine(UINT32_C( 64)), static_cast(UINT32_C(312)), static_cast(UINT32_C(156)), static_cast(UINT32_C( 31)), UINT64_C(0xB5026F5AA96619E9), static_cast(UINT32_C( 29)), UINT64_C(0x5555555555555555), static_cast(UINT32_C( 17)), UINT64_C(0x71D67FFFEDA60000), static_cast(UINT32_C( 37)), UINT64_C(0xFFF7EEE000000000), static_cast(UINT32_C( 43)), UINT64_C(6364136223846793005)>; #if defined(WIDE_INTEGER_NAMESPACE) using wide_integer_type = WIDE_INTEGER_NAMESPACE::math::wide_integer::uintwide_t(UINT32_C(256)), std::uint32_t, AllocatorType>; using distribution_type = WIDE_INTEGER_NAMESPACE::math::wide_integer::uniform_int_distribution; #else using wide_integer_type = ::math::wide_integer::uintwide_t(UINT32_C(256)), std::uint32_t, AllocatorType>; using distribution_type = ::math::wide_integer::uniform_int_distribution; #endif // Generate a random number with wide_integer_type having limbs of type LimbType. // Purosely use the default seed. random_engine_type generator; // NOLINT(cert-msc32-c,cert-msc51-cpp) distribution_type distribution; const wide_integer_type n = distribution(generator); const auto result_is_ok = (n == wide_integer_type("0xF258D22D4DB91392B5EE8CB6ABE457F8401F7AC78BC80F1CC96D191CF6F6AEA6")); return result_is_ok; } } // namespace local_random #if defined(WIDE_INTEGER_NAMESPACE) auto WIDE_INTEGER_NAMESPACE::math::wide_integer::example007_random_generator() -> bool #else auto ::math::wide_integer::example007_random_generator() -> bool #endif { const bool result_08_is_ok = local_random::generate (); const bool result_16_is_ok = local_random::generate(); const bool result_32_is_ok = local_random::generate(); const auto result_is_ok = ( result_08_is_ok && result_16_is_ok && result_32_is_ok); return result_is_ok; } // Enable this if you would like to activate this main() as a standalone example. #if defined(WIDE_INTEGER_STANDALONE_EXAMPLE007_RANDOM_GENERATOR) #include #include auto main() -> int { #if defined(WIDE_INTEGER_NAMESPACE) const auto result_is_ok = WIDE_INTEGER_NAMESPACE::math::wide_integer::example007_random_generator(); #else const auto result_is_ok = ::math::wide_integer::example007_random_generator(); #endif std::cout << "result_is_ok: " << std::boolalpha << result_is_ok << std::endl; return (result_is_ok ? 0 : -1); } #endif