Using random numbers vs hardcoded values in unit tests : <p>When I write tests, I like to use random numbers to calculate things.</p>

<p>e.g.</p>

<pre><code> func init() {
   rand.Seed(time.Now().UnixNano())
 }

  func TestXYZ(t *testing.T) {
     amount := rand.Intn(100)
     cnt := 1 + rand.Intn(10)
     for i := 0; i &lt; cnt; i++ {
       doSmth(amount)
     }
     //more stuff
  }
</code></pre>

<p>which of course has the disadvantage that </p>

<pre><code>expected := calcExpected(amount, cnt)
</code></pre>

<p>in that the expected value for the test needs to be calculated from the random values.</p>

<p>If have received criticism for this approach:</p>

<ul>
<li>It makes the test unnecessarily complex</li>
<li>Less reproduceable due to randomness</li>
</ul>

<p>I think though that without randomness, I could actually:</p>

<ul>
<li>Make up my results, e.g. the test only works for a specific value. Randomness proves my test is "robust"</li>
<li>Catch more edge cases (debatable as edge cases are usually specific, e.g. 0,1,-1)</li>
</ul>

<p>Is it really that bad to use random numbers?</p>

<p>(I realize this is a bit of an opinion question, but I am very much interested in people's point of views, don't mind downvotes).</p>
