Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 307223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:32:20+00:00 2026-05-12T07:32:20+00:00

Was thinking I could test the various answers I got in my question about

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:32:20+00:00Added an answer on May 12, 2026 at 7:32 am
    private static IEnumerable<Range<int>> GenerateRanges(int amount, int max, float density, int seed)
    {
        var r = new Random(seed);
        var commonLength = max * density / amount; // edited
        var maxLength = commonLength * 2;
        while(--amount >= 0)
        {
            var length = r.Next(maxLength);
            var start = r.Next(max - length);
            var end = start + length;
            yield return Range.Create(start, end);
        }
    }
    

    Usage could be: GenerateRanges(1000, 10000, 1.0, someTestSeed)
    or could be: GenerateRanges(1000, 10000, .5, someTestSeed) for less overlaps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thinking about avoiding code replication, I got a question that catches me every time
I wonder if you could help me with something I've been thinking about. Say
Could somebody explain to me the architecture behind chatroulette? I was thinking about a
Just thinking about the best way to build an Order form that would (from
I've been thinking about creating a Java framework that would allow programmers to specify
I have been reading a lot about test-driven development and decided that I want
Is there a plugin in eclipse that I could use to test who much
Could mapreduce be used to implement a webserver? I'm thinking something like when a
Thinking about if we modify the definition of Hamiltonian path as we need to
Thinking that the answer to this is pretty obvious but here it goes: When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.