SQLsmith  v1.2.1-5-gfacd7a8
A random SQL query generator
random.hh
Go to the documentation of this file.
1 
4 #ifndef RANDOM_HH
5 #define RANDOM_HH
6 
7 #include <random>
8 #include <utility>
9 #include <stdexcept>
10 #include <iterator>
11 
12 namespace smith {
13  extern std::mt19937_64 rng;
14 }
15 
16 template<typename T> T& random_pick(std::vector<T>& container) {
17  if (!container.size())
18  throw std::runtime_error("No candidates available");
19 
20  std::uniform_int_distribution<int> pick(0, container.size()-1);
21  return container[pick(smith::rng)];
22 }
23 
24 template<typename I>
25 I random_pick(I beg, I end) {
26  if (beg == end)
27  throw std::runtime_error("No candidates available");
28 
29  std::uniform_int_distribution<> pick(0, std::distance(beg, end) - 1);
30  std::advance(beg, pick(smith::rng));
31  return beg;
32 }
33 
34 template<typename I>
35 I random_pick(std::pair<I,I> iters) {
36  return random_pick(iters.first, iters.second);
37 }
38 
39 int d6(), d9(), d12(), d20(), d42(), d100();
40 
41 #endif