AC_DEFUN([AX_CXX_TYPE_UNIFORM_DISTRIBUTIONS],[
AC_REQUIRE([AC_PROG_CXX])
AC_LANG_PUSH([C++])
- AC_MSG_CHECKING([whether std::uniform_int_distribution<T> is supported])
- AC_TRY_COMPILE([#include <random>],[std::uniform_int_distribution<int> c;], [
- HAVE_UNIFORM_INT_DISTRIBUTION=yes
- AC_MSG_RESULT(yes)], [
- HAVE_UNIFORM_INT_DISTRIBUTION=no
- AC_MSG_RESULT(no)])
- if test "x$HAVE_UNIFORM_INT_DISTRIBUTION" = xno; then
- AC_DEFINE(uniform_int_distributon, tr1::uniform_int, [Leave undefined if std::uniform_int_distribution<T> is supported])
- fi
- AC_MSG_CHECKING([whether std::uniform_real_distribution<T> is supported])
- AC_TRY_COMPILE([#include <random>],[std::uniform_real_distribution<double> c;], [
- HAVE_UNIFORM_REAL_DISTRIBUTION=yes
- AC_MSG_RESULT(yes)], [
- HAVE_UNIFORM_REAL_DISTRIBUTION=no
- AC_MSG_RESULT(no)])
- if test "x$HAVE_UNIFORM_REAL_DISTRIBUTION" = xno; then
- AC_DEFINE(uniform_real_distributon, tr1::uniform_real, [Leave undefined if std::uniform_real_distribution<T> is supported])
- fi
+ AC_CHECK_HEADERS(tr1/random)
+ AC_CACHE_CHECK([whether std::uniform_int_distribution<T> is supported],
+ [squid_cv_std_uniform_int_distribution_works],[
+ AC_TRY_COMPILE([#include <random>],[std::uniform_int_distribution<int> c;],
+ [squid_cv_std_uniform_int_distribution_works=yes],
+ [squid_cv_std_uniform_int_distribution_works=no])
+ ])
+ SQUID_DEFINE_BOOL([HAVE_STD_UNIFORM_INT_DISTRIBUTION],
+ [$squid_cv_std_uniform_int_distribution_works],
+ [Define if c++11 std::uniform_int_distribution is supported])
+
+ AC_CACHE_CHECK([whether std::uniform_real_distribution<T> is supported],
+ [squid_cv_std_uniform_real_distribution_works],[
+ AC_REQUIRE([AC_PROG_CXX])
+ AC_LANG_PUSH([C++])
+ AC_TRY_COMPILE([#include <random>],[std::uniform_real_distribution<double> c;],
+ [squid_cv_std_uniform_real_distribution_works=yes],
+ [squid_cv_std_uniform_real_distribution_works=no])
+ ])
+ SQUID_DEFINE_BOOL([HAVE_STD_UNIFORM_REAL_DISTRIBUTION],
+ [$squid_cv_std_uniform_real_distribution_works],
+ [Define if c++11 std::uniform_real_distribution is supported])
+
AC_LANG_POP
])
#include <netinet/in_systm.h>
#endif
+#if __cplusplus && HAVE_TR1_RANDOM
+#if !HAVE_STD_UNIFORM_INT_DISTRIBUTION && !HAVE_STD_UNIFORM_REAL_DISTRIBUTION
+#include <tr1/random>
+#endif
+#endif
+
/******************************************************/
/* Typedefs for missing entries on a system */
/******************************************************/
#define NULL 0
#endif
+/***********************************************************/
+/* uniform_int_distribution backward compatibility wrapper */
+/***********************************************************/
+#if HAVE_STD_UNIFORM_INT_DISTRIBUTION
+#define xuniform_int_distribution std::uniform_int_distribution
+#else
+#define xuniform_int_distribution std::tr1::uniform_int
+#endif
+
+#if HAVE_STD_UNIFORM_REAL_DISTRIBUTION
+#define xuniform_real_distribution std::uniform_real_distribution
+#else
+#define xuniform_real_distribution std::tr1::uniform_real
+#endif
+
#endif /* SQUID_TYPES_H */
random_vector(char *aVector)
{
static std::mt19937 mt(time(0));
- static std::uniform_int_distribution<uint8_t> dist;
+ static xuniform_int_distribution<uint8_t> dist;
for (int i = 0; i < AUTH_VECTOR_LEN; ++i)
aVector[i] = static_cast<char>(dist(mt) & 0xFF);
printf("done creating hash table: %d\n", hid);
std::mt19937 mt;
- std::uniform_int_distribution<> dist(0,16);
+ xuniform_int_distribution<> dist(0,16);
while (fgets(buf, BUFSIZ, stdin)) {
buf[strlen(buf) - 1] = '\0';
ntlm_make_nonce(char *nonce)
{
static std::mt19937 mt(time(0));
- static std::uniform_int_distribution<uint8_t> dist;
+ static xuniform_int_distribution<uint8_t> dist;
for (int i = 0; i < NTLM_NONCE_LEN; ++i)
nonce[i] = static_cast<char>(dist(mt) & 0xFF);
// actually matching whether the random value is above
// or below the configured threshold ratio.
static std::mt19937 mt;
- static std::uniform_real_distribution<> dist(0, 1);
+ static xuniform_real_distribution<> dist(0, 1);
const double random = dist(mt);
// NP: this will likely produce the same randomness sequences for each worker
// since they should all start within the 1-second resolution of seed value.
static std::mt19937 mt(static_cast<uint32_t>(getCurrentTime() & 0xFFFFFFFF));
- static std::uniform_int_distribution<uint32_t> newRandomData;
+ static xuniform_int_distribution<uint32_t> newRandomData;
/* create a new nonce */
newnonce->nc = 0;
// relative to each other to prevent waves of synchronised activity.
static std::mt19937 rng;
auto third = (delta_ish/3.0);
- std::uniform_real_distribution<> thirdIsh(delta_ish - third, delta_ish + third);
+ xuniform_real_distribution<> thirdIsh(delta_ish - third, delta_ish + third);
delta_ish = thirdIsh(rng);
}
* swap directories
*/
std::mt19937 mt(static_cast<uint32_t>(getCurrentTime() & 0xFFFFFFFF));
- std::uniform_int_distribution<> dist(0, j);
+ xuniform_int_distribution<> dist(0, j);
swap_index = dist(mt);
}
// sizeof() counts the terminating zero at the end of characters
// and the distribution is an 'inclusive' value range, so -2
// TODO: add \0 character (needs reporting adjustments to print it as \0)
- static std::uniform_int_distribution<uint8_t> dist(0, sizeof(characters)-2);
+ static xuniform_int_distribution<uint8_t> dist(0, sizeof(characters)-2);
SBuf buf;
buf.reserveCapacity(length);
printf("done creating hash table: %d\n", hid);
std::mt19937 mt;
- std::uniform_int_distribution<> dist(0,16);
+ xuniform_int_distribution<> dist(0,16);
while (fgets(buf, BUFSIZ, stdin)) {
buf[strlen(buf) - 1] = '\0';
main(int argc, char *argv[])
{
std::mt19937 generator;
- std::uniform_int_distribution<int> distribution;
+ xuniform_int_distribution<int> distribution;
auto nextRandom = std::bind (distribution, generator);
{