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 6697791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:30:08+00:00 2026-05-26T06:30:08+00:00

I am in need of a way to randomly split a 1-dimensional range of

  • 0

I am in need of a way to randomly split a 1-dimensional range of values (i.e. continuous integers) into k sections. Just using a pseudo-random generator to pick split points would technically get the job done. However it allows for possibility of ranges either being very tiny (conversely very large). I’ve been looking for a way to generally solve this problem without resorting to hard-coded range limits.

I have found this article. It is concerned with 2d terrain generation. But it faces the same issue and presents a solution. You can see the Polygons section, where the author mentions Lloyd relaxation. What that whole thing derives from is Voronoi diagrams, and it works with 2d ranges. Furthermore, if you look at the algorithm for building the Voronoi diagram that Lloyd relaxation needs, it starts with:

let *(z) be the transformation *(z) = (zx, zy + d(z)), where d(z) is a parabola with minimum at z

Naturally, I don’t have parabolas in 1d.

It is not clear to me how to achieve the same results in my case of 1d range. Or maybe there is a different/better approach to the problem?

  • 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-26T06:30:08+00:00Added an answer on May 26, 2026 at 6:30 am

    I didn’t get into the details of his code, but what he did with Voronoi diagrams in 2d, then choosing the center of the polygons as new points and remaking the Voronoi diagrams gives me this idea:

    1. Randomly select your points
    2. Compute midways between your points
        -> The two midways on the two sides of each point, is like
           its Voronoi polygon in the Voronoi diagram
        -> So let's call the range between these two "midways" a Voronoi range!
    3. Replace each point by the center of its Voronoi range
    4. If you want the values to be less random, loop back to step 2
    5. The ranges you are looking for are the Voronoi ranges of the last results.
    

    Let’s follow this by an example. For simplicity, let’s assume we are working on continuous ranges.

    So you start with range [0, 80] and you want to divide it in 15 ranges.

    Let’s say your 15 random numbers after being sorted are (generated by a C program:)

    1 5 12 17 19 21 26 31 38 47 52 54 56 67 71
    

    The midpoints are:

    1   5   12   17   19   21   26   31   38   47   52   54   56   67   71
      ^   ^    ^    ^    ^    ^    ^    ^    ^    ^    ^    ^    ^    ^
      |   |    |    |    |    |    |    |    |    |    |    |    |    |
      3  8.5 14.5  18   20  23.5 28.5 34.5 42.5 49.5  51   55  61.5  69
    

    So your ranges become:

    [0, 3], [3, 8.5], [8.5, 14.5], [14.5, 18], [18, 20], 
    [20, 23.5], [23.5, 28.5], [28.5, 34.5], [34.5, 42.5], [42.5, 49.5],
    [49.5, 51], [51, 55], [55, 61.5], [61.5, 69], [69, 80]
    

    If you want to visualize this, it looks like this (as best I can show it in text):

    +..+.....+.....+..+.+...+....+.....+.......+......++...+......+......+.........+
    

    Where the . show numbers from 0 to 80 and + show the edges of Voronoi ranges.

    Now, let’s apply step 3.

    1   5   12   17   19   21   26   31   38   47   52   54   56   67   71
      ^   ^    ^    ^    ^    ^    ^    ^    ^    ^    ^    ^    ^    ^
      |   |    |    |    |    |    |    |    |    |    |    |    |    |
    0 3  8.5 14.5  18   20  23.5 28.5 34.5 42.5 49.5  51   55  61.5  69 80
     ^  ^   ^     ^   ^    ^    ^    ^    ^    ^    ^    ^    ^     ^  ^
     |  |   |     |   |    |    |    |    |    |    |    |    |     |  |
    1.5 | 11.5  16.25 19 21.75 26  31.5 38.5  46  50.25 53  58.25 65.25|
       5.75                                                          74.5
    

    So let’s see now see how the Voronoi ranges look like with the new points:

    1.5  5.75 11.5  16.25  19  21.75 26  31.5 38.5  46  50.25 53  58.25 65.25 74.5
       ^     ^    ^       ^   ^     ^   ^    ^    ^    ^     ^    ^    ^     ^
       |     |    |       |   |     |   |    |    |    |     |    |    |     |
     3.625 8.625 13.875 17.625|  23.875 |   35  42.25 48.125 | 55.625 61.75 69.875
                            20.375    28.75               51.625
    

    Now your ranges are (it’s starting to look ugly, but bear with me)

    [0, 3.625], [3.625, 8.625], [8.625, 13.875],
    [13.875, 17.625], [17.625, 20.375], [20.375, 23.875],
    [23.875, 28.75], [28.75, 35], [35, 42.25],
    [42.25, 48.125], [48.125, 51.625], [51.625, 55.625],
    [55.625, 61.75], [61.75, 69.875], [69.875, 80]
    

    So now let’s take a look at how this distribution of points looks like:

    +...+....+....+...+..+..+....+.....+.......+....+...+...+.....+.......+........+
    

    Now let’s compare the two distributions:

    First one 
      |
      V
    +..+.....+.....+..+.+...+....+.....+.......+......++...+......+......+.........+
    +...+....+....+...+..+..+....+.....+.......+....+...+...+.....+.......+........+
      ^
      |
    Second one
    

    Looks better, doesn’t it? That’s exactly what he has done in the article you found with 2d Voronoi polygons applied to 1d ranges.

    (Excuse me for any possible computation errors)

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

Sidebar

Related Questions

I have an array of double values vals, I need to randomly index into
Is there a good algorithm to split a randomly generated number into three buckets,
What's the fastest way to randomly generate numbers, either randomly or simulating random? I
I need to randomly 'sort' a list of integers (0-1999) in the most efficient
I need to randomly select, in an efficient way, 10 rows from my table.
I have a large dataset that I need to divide randomly into 5 almost
I'm writing a program that randomly assembles mathematical expressions using the values stored in
Need a way to allow sorting except for last item with in a list.
I need a way to represent information about Weeks and Days as such: W1:
I need a way to get the friend ids of a user. I written

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.