title: Can we take a `std::chrono::milliseconds` variable from a range of the same type?
body: <p>I have constructed an function that takes as input a specific date and return this date in <code>std::chrono::milliseconds</code> format. </p>
  
  <pre><code>milliseconds lowerRangeBound = TimeStamp(mm, dd, HH, MM, SS, yyyy);
  </code></pre>
  
  <p>For example,</p>
  
  <pre><code>milliseconds a = TimeStamp(8/*month*/, 23/*day*/, 14/*hours*/, 46/*minutes*/, 32/*seconds*/, 2017/*year*/);
  </code></pre>
  
  <p>returns in a converted string format: <code>2017.08.23-14.46.32</code></p>
  
  <p>What I want now to do and does not work is given two dates (<code>milliseconds</code>) to take a random date inside the range defined by these two dates. For example, given</p>
  
  <pre><code>milliseconds a = TimeStamp(8/*month*/, 23/*day*/, 13/*hours*/, 46/*minutes*/, 32/*seconds*/, 2017/*year*/);
  milliseconds b = TimeStamp(10/*month*/, 23/*day*/, 13/*hours*/, 46/*minutes*/, 32/*seconds*/, 2017/*year*/);
  </code></pre>
  
  <p>the expected output is a <code>milliseconds c</code> which in string format is a date like this, <code>2017.09.13-12.56.12</code>. Note that the desired output is a <code>milliseconds</code>, the string format is provided in order to speak in <a href="https://stackoverflow.com/questions/12835577/how-to-convert-stdchronotime-point-to-calendar-datetime-string-with-fraction">readable format</a>.</p>
  
  <p>What I have tried so far is to convert each <code>milliseconds</code> variable into <code>long</code> number (<code>.count()</code>) and get a <a href="https://stackoverflow.com/questions/12657962/how-do-i-generate-a-random-number-between-two-variables-that-i-have-stored">random</a> <code>long</code> in the range <code>[a,b]</code>. However,the output date is something irrelevant: <code>1977.12.06-16.27.02</code>.</p>
  
  <p>Could you please give a hand on this?</p>
  
  <p>Thank you in advance.</p>
  
  <p><strong>EDIT:</strong> The code bellow is inspired by this <a href="https://stackoverflow.com/questions/12835577/how-to-convert-stdchronotime-point-to-calendar-datetime-string-with-fraction">link</a></p>
  
  <pre><code>milliseconds TimeStamp(int mm, int dd, int HH, int MM, int SS, int yyyy) {
  
      tm ttm = tm();
      ttm.tm_year = yyyy - 1900; // Year since 1900
      ttm.tm_mon = mm - 1; // Month since January 
      ttm.tm_mday = dd; // Day of the month [1-31]
      ttm.tm_hour = HH; // Hour of the day [00-23]
      ttm.tm_min = MM;
      ttm.tm_sec = SS;
  
      time_t ttime_t = mktime(&amp;ttm);
      system_clock::time_point time_point_result = std::chrono::system_clock::from_time_t(ttime_t);
      milliseconds now_ms = std::chrono::time_point_cast&lt;std::chrono::milliseconds&gt;(time_point_result).time_since_epoch();
      return now_ms;
  }
  
  milliseconds getRandomTimestamp(int mm_1, int dd_1, int HH_1, int MM_1, int SS_1, int yyyy_1,
      int mm_2, int dd_2, int HH_2, int MM_2, int SS_2, int yyyy_2, int N) {
  
      milliseconds lowerRangeBound = fixedTimeStamp(mm_1, dd_1, HH_1, MM_1, SS_1, yyyy_1);
      milliseconds upperRangeBound = fixedTimeStamp(mm_2, dd_2, HH_2, MM_2, SS_2, yyyy_2);
  
      long lowerRange_ = lowerRangeBound.count();
      long upperRange_ = upperRangeBound.count();
  
      //long output = rand() % (upperRange_ - lowerRange_ + 1) + lowerRange_;
      // rand() replaced after @Jarod42's suggestion.
      std::default_random_engine generator;
      std::uniform_int_distribution&lt;int&gt; distribution(lowerRange_, upperRange_);
      long output = distribution(generator);        
  
      std::chrono::duration&lt;long&gt; dur(output);
      return dur;
  }
  </code></pre>