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

  • SEARCH
  • Home
  • 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 1065515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:48:49+00:00 2026-05-16T19:48:49+00:00

For example, say I enter ’10’ for the amount of values, and ‘10000’ as

  • 0

For example, say I enter ’10’ for the amount of values, and ‘10000’ as a total amount.

The script would need to randomize 10 different numbers that all equal up to 10000. No more, no less.

But it needs to be dynamic, as well. As in, sometimes I might enter ‘5’ or ‘6’ or even ’99’ for the amount of values, and any number (up to a billion or even higher) as the total amount.

How would I go about doing this?

EDIT: I should also mention that all numbers need to be a positive integer

  • 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-16T19:48:49+00:00Added an answer on May 16, 2026 at 7:48 pm

    The correct answer here is unbelievably simple.

    Just imagine a white line, let’s say 1000 units long.

    You want to divide the line in to ten parts, using red marks.

    VERY SIMPLY, CHOOSE NINE RANDOM NUMBERS and put a red paint mark at each of those points.

    It’s just that simple. You’re done!

    Thus, the algorithm is:

    (1) pick nine random numbers between 0 and 1000
    (2) put the nine numbers, a zero, and a 1000, in an array
    (3) sort the array
    (4) using "subtraction" get the ten "distances" between array values

    You’re done.

    (Obviously if you want to have no zeros in your final set, in part (1) simply rechoose another random number if you get a collision.)

    Ideally as programmers, we can "see" visual algorithms like this in our heads — try to think visually whatever we do!


    Footnote – for any non-programmers reading this, pls note that this is like "the first thing you learn when studying computer science!" i.e. I do not get any credit for this, I just typed in the trivial answer.

    FTR another common algorithm everyone knows assuming you’re dealing with fractions. Get 10 random numbers. Add them. multiply or divide them all by some number, so that, the total is the desired total! It’s that easy if dealing with fractions.

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

Sidebar

Related Questions

Example: say I want to open a file. If I get a FileNotFoundException ,
Currently I have a timestamp for example say, 2012-06-23 14:24:07.975 and two times -
i have problem use link_to_remote link_to_remote document example say link_to_remote Delete this post, :update
Is intercontainer communication possible within Apache tomcat? For example: Say you have 2 rest
can you get the last or newly added element in std::set? for example say
for example lets say your pulling data from somewhere and you put it in
For example lets say I have a JSON object that contains states and cities.
To use as an example: lets say that I have 2 EditText s and
How do you elegantly format a timespan to say example 1 hour 10 minutes
I have 2 websites, lets say - example.com and example1.com example.com has a database

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.