// (C) Copyright Nick Thompson 2018. // (C) Copyright Matt Borland 2021. // Use, modification and distribution are subject to 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 namespace boost { namespace math { // To stress test, set global_seed = 0, global_size = huge. static const std::size_t global_seed = 0; static const std::size_t global_size = 128; template::value, bool>::type = true> std::vector generate_random_vector(std::size_t size, std::size_t seed) { if (seed == 0) { std::random_device rd; seed = rd(); } std::vector v(size); std::mt19937 gen(seed); std::normal_distribution dis(0, 1); for(std::size_t i = 0; i < v.size(); ++i) { v[i] = dis(gen); } return v; } template::value, bool>::type = true> std::vector generate_random_vector(std::size_t size, std::size_t seed) { if (seed == 0) { std::random_device rd; seed = rd(); } std::vector v(size); std::mt19937 gen(seed); // Rescaling by larger than 2 is UB! std::uniform_int_distribution dis(std::numeric_limits::lowest()/2, (std::numeric_limits::max)()/2); for (std::size_t i = 0; i < v.size(); ++i) { v[i] = dis(gen); } return v; } }} // Namesapces