Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • 43
    Tight coupling shows its head. Pass in the object that generates the random numbers. Then during testing you can pass an object that generates a specified set of numbers for which you know what the deck looks like after the shuffle. You can test the randomness of your random number generator separately. Commented May 3, 2012 at 18:41
  • 1
    I would strongly consider using an existing library routine for shuffle (java Collections.shuffle() or similar). There is a cautionary tale to be read at developer.com/tech/article.php/616221/… about writing a flawed shuffle algorithm. For writing a d6() function, one would test it enough to be confident that it won't generate a number out of range and then do a chi squared test on the distribution (chi squared being rather sensitive to pseudo random sequences). Look also at the serial correlation coefficient. Commented May 3, 2012 at 20:50
  • "This relies on the random function always returning the same values given the same seed. However, this is sometimes an invalid assumption." I followed the link, and I'm not seeing the invalid assumption. It says quite plainly: "If the same seed is used repeatedly, the same series of numbers is generated." Commented May 3, 2012 at 22:45
  • @Kyralessa "The implementation of the random number generator in the Random class is not guaranteed to remain the same across major versions of the .NET Framework." So not a huge concern, but still something to consider. Commented May 3, 2012 at 22:52
  • 4
    @Kyralessa I missed the important half of that quote: "As a result, your application code should not assume that the same seed will result in the same pseudo-random sequence in different versions of the .NET Framework." Commented May 3, 2012 at 23:01