title: How to create an array of pseudo-random numbers that are spread out over an interval?
body: <p>I would like to create an array of n (<code>steps</code>) integers within an interval [a (<code>min</code>), b (<code>max</code>)] which can be done like this (there are probably smarter ways):</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function randomFromInterval(min, max, steps) {
    return new Array(steps).fill(0).map(n =&gt; Math.floor(Math.random() * (max - min + 1) + min));
  }
  
  console.log(randomFromInterval(1, 100, 10));</code></pre>
  </div>
  </div>
  </p>
  
  <p>Unfortunately, with <a href="https://xkcd.com/221/" rel="nofollow noreferrer">truly random integers</a>, it could happen that the result of <code>randomFromInterval(1, 100, 5)</code> is for example <code>[1,2,3,4,5]</code> which I would like to mitigate. The values of <code>randomFromIntervalButSpread(min, max, steps)</code> should therefore be spread out over the interval in such a way that</p>
  
  <pre><code>randomFromIntervalButSpread(0, 4, 5) =&gt; [0,1,2,3,4]
  randomFromIntervalButSpread(10, 60, 5) =&gt; [1X,2X,3X,4X,5X] // X being 0-9
  .
  .
  .
  </code></pre>
  
  <p>To summarize: The numbers should be random in the sense that if steps > |[min, max]| the results differ from iteration to iteration but are never grouped together within the interval.</p>