5 #ifndef ICE_UTIL_RANDOM_H
6 #define ICE_UTIL_RANDOM_H
11 #ifdef ICE_CPP11_COMPILER
15 # include <functional>
18 namespace IceUtilInternal
21 ICE_API void generateRandom(
char*,
size_t);
22 ICE_API unsigned int random(
int = 0);
24 #ifdef ICE_CPP11_COMPILER
27 void shuffle(T first, T last)
29 std::random_device rd;
30 std::mt19937 rng(rd());
31 std::shuffle(first, last, rng);
36 struct RandomNumberGenerator :
public std::unary_function<std::ptrdiff_t, std::ptrdiff_t>
38 std::ptrdiff_t operator()(std::ptrdiff_t d)
40 return static_cast<std::ptrdiff_t
>(IceUtilInternal::random(
static_cast<int>(d)));
45 void shuffle(T first, T last)
47 RandomNumberGenerator rng;
48 random_shuffle(first, last, rng);