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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:24:13+00:00 2026-05-26T16:24:13+00:00

I need to create a function that will generate 2 random numbers between x

  • 0

I need to create a function that will generate 2 random numbers between x and y (e.g. x = 1, y = 20) which when added will not involve regrouping / carryover or which when subracted will not involve borrowing.

For example,

18 + 1 = good
14 + 5 = good
18-7 = good
29 - 8 = good

15 + 6 = bad
6 + 7 = bad
21 - 3 = bad
36 - 8 = bad etc.

I want to create a simple worksheet generator that will generate sample problems using the requirements above.

I guess I could always convert the number to string, get the right most digit for each of the 2 numbers, convert them back to integer, and test if one is greater than the other. Repeat for all the digit. Only thing is, that is so damn ugly (read inefficient). I am sure that there is a better way. Anyone have any suggestions? Thanks

  • 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-26T16:24:14+00:00Added an answer on May 26, 2026 at 4:24 pm
    using System;
    
    class Sample {
        static void Main() {
            var rnd = new Random();
            var x = 1;
            var y = 20;
            var a = rnd.Next(x, y);
            var b = rnd.Next(x, y);
            var op = '+';
            Console.WriteLine("{0} {2} {1} = {3}", a, b, op , isValid(a, b, op)? "good":"bad");
            op = '-';
            Console.WriteLine("{0} {2} {1} = {3}", a, b, op , isValid(a, b, op)? "good":"bad");
        }
        static bool isValid(int x, int y, char op){
            int a = x % 10;
            int b = y % 10;
            switch (op){
            case '+':
                return a + b < 10;
            case '-':
                return x >= y && a - b >= 0;
            default:
                throw new Exception(String.Format("unknown operator '{0}'", op));
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking to create a reusable function that will generate a random key with
I need to create a function that uses a loop. This function will open
I need to create a javascript function that checks if it has been a
Need to create a custom DNS name server using C which will check against
I need to create a report using SSRS 2008 that will show the top
i need to create a function in my application to set its available memory
I need to create a php search function for names and need to change
I need to create an XML schema that looks something like this: <xs:element name=wrapperElement>
I have a C program in which I need to create a whole family
Hello I have a jQuery function that will send to a php file some

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.