title: What's the difference between Math.random() >= 0.5 and Math.random() - 0.5
body: <p>I want to generate an array of length <code>n</code>, and the elements of the array are the random integer between 2 and 32. I use the function follow but I find that 17 will always be the first element of the returned array. What's more, when I change to sort function to <code>sort(() =&gt; Math.random() - 0.5)</code>, it works well.</p>
  
  <p>So I am confused that what's the difference between<code>Math.random() &gt;= 0.5</code> and <code>Math.random() - 0.5</code>? And how the difference affects the <code>sort()</code> function?</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>const fn = (n) =&gt; {
    let arr = [];
    for (let i = 2; i &lt; 33; i++) {
      arr.push(i);
    }
    return arr.sort(() =&gt; Math.random() &gt;= 0.5).slice(0, n)
  }</code></pre>
  </div>
  </div>
  </p>