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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T06:13:06+00:00 2026-05-19T06:13:06+00:00

I am trying to automatically generate a large set of test data and I

  • 0

I am trying to automatically generate a large set of test data and I am struggling to understand how to generate a set of random values required.

I need to create a set of random values which occur within different ranges. The sum of the resulting values must be over or under a predetermined value depending on the test case.

For example,

Value | Minimum value | Maximum Value
A | 100 | 300
B | 200 | 500
C | 300 | 600
D | 100 | 300

If the sum of values must be greater than 800 a valid solution would be

A = 200
B = 400
C = 500
D = 100

If the sum of values must be less than 800 a valid solution would be

A = 100
B = 200
C = 300
D = 100

Can this problem only be solved using an optimisation function? Is there any other way to calculate the values of ABCD?

I am looking to solve this problem using SQL but would be interested to hear a pseudo-code approach too.

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

    Try and try again until you get what you want.

    declare @T table (Value char(1), MinValue int, MaxValue int)
    insert into @T values('A', 100, 300)
    insert into @T values('B', 200, 500)
    insert into @T values('C', 300, 600)
    insert into @T values('D', 100, 300)
    
    declare @R table (Value char(1), Rnd int)
    
    declare @Sum int
    
    while 0=0
    begin
        delete @R
        insert into @R
        select Value, round(((MaxValue - MinValue -1) * rand() + MinValue), 0) as Rnd
            from @T
    
        select @Sum = sum(Rnd) from @R
        if @Sum > 800
            break
    end
    
    select *, @Sum
    from @R
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a process to automatically generate thumbnails of the images uploaded
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Currently I'm trying to automatically generate a create script for all my SQL jobs
I am trying to learn MVC. I want to automatically generate the required view
I'm trying to make a script that automatically starts uploading after the data has
I am trying to use PHP and MySQL to automatically generate a list like
I'm trying to automatically generate a line chart using VBA and Excel where each
I am trying to automatically generate a bunch of images all containing a border,
I am using reportlab to generate a pdf report automatically from dynamic data. As
I am trying to get jsdoc to automatically generate when I save my javascript

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.