39#ifndef BLOCXX_SECURE_RAND_HPP_INCLUDE_GUARD_
40#define BLOCXX_SECURE_RAND_HPP_INCLUDE_GUARD_
43#include "blocxx/BLOCXX_config.h"
45#ifdef BLOCXX_HAVE_OPENSSL
64 template <
typename T>
struct assert_unsigned_integer_type;
66 template <>
struct assert_unsigned_integer_type<unsigned char> { };
67 template <>
struct assert_unsigned_integer_type<unsigned short> { };
68 template <>
struct assert_unsigned_integer_type<unsigned int> { };
69 template <>
struct assert_unsigned_integer_type<unsigned long> { };
70 template <>
struct assert_unsigned_integer_type<unsigned long long> { };
74 template <
typename T>
struct assert_integer_type;
76 template <>
struct assert_integer_type<char> { };
78 template <>
struct assert_integer_type<signed char> { };
79 template <>
struct assert_integer_type<short> { };
80 template <>
struct assert_integer_type<int> { };
81 template <>
struct assert_integer_type<long> { };
82 template <>
struct assert_integer_type<long long> { };
84 template <>
struct assert_integer_type<unsigned char> { };
85 template <>
struct assert_integer_type<unsigned short> { };
86 template <>
struct assert_integer_type<unsigned int> { };
87 template <>
struct assert_integer_type<unsigned long> { };
88 template <>
struct assert_integer_type<unsigned long long> { };
92 template <
typename T>
struct assert_float_type;
94 template <>
struct assert_float_type<float> { };
95 template <>
struct assert_float_type<double> { };
96 template <>
struct assert_float_type<long double> { };
98 template <
typename Un
signedInt>
99 UnsignedInt rand_uint_lt(UnsignedInt n);
101 template <
typename Integer>
102 Integer rand_range(Integer min_value, Integer max_value);
104 template <
typename Real>
105 Real rand_unit_interval();
113 BLOCXX_COMMON_API
void rand_init();
117 BLOCXX_COMMON_API
void rand_save_state();
127 BLOCXX_COMMON_API
unsigned char * rand(
unsigned char * buf, std::size_t n);
137 template <
typename Un
signedInt>
138 inline UnsignedInt rand_uint()
140 Impl::assert_unsigned_integer_type<UnsignedInt> dummy;
142 rand(
reinterpret_cast<unsigned char *
>(&n),
sizeof(n));
155 template <
typename Un
signedInt>
156 inline UnsignedInt rand_uint_lt(UnsignedInt n)
158 Impl::assert_unsigned_integer_type<UnsignedInt> dummy;
159 return Impl::rand_uint_lt(n);
172 template <
typename Integer>
173 inline Integer rand_range(Integer min_val, Integer max_val)
175 Impl::assert_integer_type<Integer> dummy;
176 return Impl::rand_range(min_val, max_val);
188 template <
typename Real>
189 inline Real rand_unit_interval()
191 Impl::assert_float_type<Real> dummy;
192 return Impl::rand_unit_interval<Real>();
#define BLOCXX_DECLARE_EXCEPTION(NAME)
Declare a new exception class named <NAME>Exception that derives from Exception This macro is typical...