Note that there are some explanatory texts on larger screens.

plurals
  1. POTesting for Random Value - Thoughts on this Approach?
    text
    copied!<p>OK, I have been working on a random image selector and queue system (so you don't see the same images too often).</p> <p>All was going swimmingly (as far as my crappy code does) <strong>until</strong> I got to the random bit. I wanted to test it, but how do you test for it? There is no <code>Debug.Assert(i.IsRandom)</code> (sadly) :D</p> <p>So, I got my brain on it after watering it with some tea and came up with the following, I was just wondering if I could have your thoughts?</p> <ul> <li>Basically I knew the <strong>random</strong> bit was the problem, so I ripped that out to a delegate (which would then be passed to the objects constructor).</li> <li>I then created a class that pretty much performs the same logic as the <em>live</em> code, but remembers the value selected in a private variable.</li> <li>I then threw that delegate to the live class and tested against that:</li> </ul> <p>i.e.</p> <pre><code>Debug.Assert(myObj.RndVal == RndIntTester.ValuePassed); </code></pre> <p>But I couldn't help but think, <strong>was I wasting my time?</strong> I ran that through lots of iterations to see if it fell over at any time etc.</p> <p>Do you think I was wasting my time with this? Or could I have got away with:</p> <p><img src="https://imgs.xkcd.com/comics/random_number.png" alt="Awesome Random Number Generator"></p> <p><a href="https://stackoverflow.com/questions/122741/testing-for-random-value-thoughts-on-this-approach#122765">GateKiller's answer</a> reminded me of this:</p> <p><img src="https://www.random.org/analysis/dilbert.jpg" alt="Dilbert Random"></p> <h2>Update to Clarify</h2> <ul> <li><strong>I should add that I basically never want to see the same result more than X number of times from a pool of Y size.</strong></li> <li>The addition of the test container basically allowed me to see if any of the previously selected images were "randomly" selected.</li> <li>I guess technically the thing here being tested in not the RNG (since I never wrote that code) but the fact that am I expecting <em>random</em> results from a limited pool, and I want to track them.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload