Was thinking I could test the various answers I got in my question about an algorithm for collapsing ranges. So I was thinking I should create a method that creates a whole bunch of ranges and see how the various methods handles it.
But when it comes to generating random stuff I am not very good. I created something like this:
private static IEnumerable<Range<int>> GenerateRanges()
{
var r = new Random();
var n = 10000;
while(--n >= 0)
{
var start = r.Next(10000);
var end = r.Next(10000);
if (end < start)
Swap(ref start, ref end);
yield return Range.Create(start, end);
}
}
This creates a lot of ranges of course, but they do not give particularly interesting results since I always end up with only one range after collapsing them. How can I create more interesting ranges?