title: Uniform random distribution "base class" for both int and double?
body: <p>I'm trying to make a function that will fill a list with random numbers, and based on the type of the list items it should generate either integer or floating point numbers. So far I've come up with the following code, and it works: </p>
  
  <pre><code>template &lt;typename T&gt;
  void generateRandom(list&lt;T&gt;&amp; numberList){
      default_random_engine randomGenerator(random_device{}());
  
      if( typeid(T) == typeid(int) ){
          uniform_int_distribution&lt;T&gt; distribution(1000, 2000);
          auto myGenerator = bind(distribution, randomGenerator);
          generate(numberList.begin(), numberList.end(), myGenerator);
      }
      else if( typeid(T) == typeid(double) ){
          uniform_real_distribution&lt;T&gt; distribution(1000.0, 2000.0);
          auto myGenerator = bind(distribution, randomGenerator);
          generate(numberList.begin(), numberList.end(), myGenerator);
      }
      else{
          return;
      }
  
  }
  </code></pre>
  
  <p>However, I'm not really satisfied with this solution. It just feels like there should be some way to break out everything but the actual distribution from that IF statement. Something like:</p>
  
  <pre><code>template &lt;typename T&gt;
  void generateRandom(list&lt;T&gt;&amp; numberList){
      default_random_engine randomGenerator(random_device{}());
  
      X distribution;
      if( typeid(T) == typeid(int) )
          distribution = uniform_int_distribution&lt;T&gt;(1000, 2000);
      else if( typeid(T) == typeid(double) )
          distribution = uniform_real_distribution&lt;T&gt;(1000.0, 2000.0);
      else
          return;
  
      auto myGenerator = bind(distribution, randomGenerator);
      generate(numberList.begin(), numberList.end(), myGenerator);
  }
  </code></pre>
  
  <p>(X is a placeholder for what's missing here)</p>
  
  <p>But since <code>uniform_int_distribution</code> and <code>uniform_real_distribution</code> don't have a common base class, how would that be possible? I have tried playing around with function pointers and functors, but I never seem to get past that IF-statement, and it's annoying. Can this be solved in a more elegant way?</p>
  
  <p>NOTE: It's part of a school assignment, and we have to use <code>generate()</code> and the <code>&lt;random&gt;</code> functions and templates to generate the random numbers. I think my original solution is acceptable, I just don't like the look of those duplicate lines of code in the IF-statement... :)</p>