26 #ifndef CRYPTO3_ALGEBRA_RANDOM_ELEMENT_HPP
27 #define CRYPTO3_ALGEBRA_RANDOM_ELEMENT_HPP
31 #include <nil/crypto3/multiprecision/debug_adaptor.hpp>
32 #include <nil/crypto3/multiprecision/cpp_bin_float.hpp>
33 #include <nil/crypto3/multiprecision/cpp_int.hpp>
35 #include <boost/core/ignore_unused.hpp>
37 #include <boost/random/independent_bits.hpp>
38 #include <boost/random/discard_block.hpp>
39 #include <boost/random/xor_combine.hpp>
40 #include <boost/random/mersenne_twister.hpp>
41 #include <boost/random/random_number_generator.hpp>
42 #include <boost/random/uniform_int.hpp>
43 #include <boost/random/uniform_smallint.hpp>
44 #include <boost/random/discrete_distribution.hpp>
45 #include <boost/random/random_device.hpp>
55 typename DistributionType = boost::random::uniform_int_distribution<typename FieldType::integral_type>,
56 typename GeneratorType = boost::random::mt19937>
58 typename FieldType::value_type>::type
61 using field_type = FieldType;
62 using distribution_type = DistributionType;
63 using generator_type = GeneratorType;
65 distribution_type d(0, field_type::modulus);
67 boost::random_device rd;
70 typename field_type::value_type value(d(rd));
77 typename DistributionType = boost::random::uniform_int_distribution<typename FieldType::integral_type>,
78 typename GeneratorType = boost::random::mt19937>
80 typename FieldType::value_type>::type
83 using field_type = FieldType;
84 using distribution_type = DistributionType;
85 using generator_type = GeneratorType;
87 typename field_type::value_type::data_type data;
88 const std::size_t data_dimension = field_type::arity / field_type::underlying_field_type::arity;
90 for (
int n = 0; n < data_dimension; ++n) {
92 random_element<typename FieldType::underlying_field_type, distribution_type, generator_type>();
95 return typename field_type::value_type(data);
98 template<
typename CurveGroupType,
99 typename DistributionType =
100 boost::random::uniform_int_distribution<typename CurveGroupType::field_type::integral_type>,
101 typename GeneratorType = boost::random::mt19937>
102 typename std::enable_if<is_curve_group<CurveGroupType>::value,
typename CurveGroupType::value_type>::type
105 using curve_type =
typename CurveGroupType::curve_type;
106 using field_type =
typename curve_type::scalar_field_type;
107 using distribution_type = boost::random::uniform_int_distribution<typename field_type::integral_type>;
108 using generator_type = GeneratorType;
110 return random_element<typename curve_type::scalar_field_type, distribution_type, generator_type>() *
111 CurveGroupType::value_type::one();
std::enable_if< is_field< FieldType >::value &&!(is_extended_field< FieldType >::value), typename FieldType::value_type >::type random_element()
Definition: random_element.hpp:59
static const bool value
Definition: algebra/include/nil/crypto3/algebra/type_traits.hpp:106