title: Unit Testing with functions that return random results
body: <p>I don't think that this is specific to a language or framework, but I am using xUnit.net and C#.</p>
  
  <p>I have a function that returns a random date in a certain range. I pass in a date, and the returning date is always in range of 1 to 40 years before the given date.</p>
  
  <p>Now I just wonder if there is a good way to unit test this. The best approach seems to be to create a loop and let the function run i.e. 100 times and assert that every of these 100 results are in the desired range, which is my current approach.</p>
  
  <p>I also realize that unless I am able to control my Random generator, there will not be a perfect solution (after all, the result IS random), but I wonder what approaches you take when you have to test functionality that returns a random result in a certain range?</p>