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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:39:41+00:00 2026-06-15T18:39:41+00:00

I have a site that requires random mathematical problems to be generated based on

  • 0

I have a site that requires random mathematical problems to be generated based on 3 parameters: operator (addition, subtraction, multiplication, division), regrouping (to carry or not to carry), and columns (one or two). I’ve been trying to wrap my head around how to go about doing this, but everything I come up with has a flaw in some way or other.

Here is what I am working with currently:

function create_problem($operator, $regrouping, $columns){
    $top = rand(1,9);
    $bottom = rand(1,9);

    if($operator == "+"){
        if($columns == 1 && $regrouping === false){
            $result = array(
                'top' => $top,
                'bottom' => $bottom,
                'formula' => "$top.$operator.$bottom"
            );
        }
        if($columns == 2){
            if($regrouping === false){
                if($top+$bottom > 9){
                    $diff = ($top+$bottom)-10;
                    $top = $diff+rand(1, 3);    
                }
                $result = array(
                    'top' => $top,
                    'bottom' => $bottom,
                    'formula' => "$top.$operator.$bottom"
                );
            }else{
                if($top+$bottom < 10){
                    $top = rand(1, $bottom+1);
                }
            }
        }
    }
    return $result;
}

If anyone has dealt with this, or if anyone has any pointers, I would be most appreciative!

  • 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-06-15T18:39:42+00:00Added an answer on June 15, 2026 at 6:39 pm

    this function first checks for regrouping, and produces random numbers so that the sum of common-column numbers are less than 10 (for no-carry) or greater or equal to 10 (for carry).

    function create_problem($operator, $regrouping, $columns){
    $x1 = '';
    $x2 = '';
    $y1 = '';
    $y2 = '';
    if ($regrouping){
        if ($columns == 2){
        $x1 = rand(1,9);
        $x2 = rand(0,9);
        $y1 = rand(9-$x1,9);
        $y2 = rand(10-$x2,9);
        } else {
        $x1 = rand(1,9);
        $y1 = rand(9-$x1,9);
        }
    } else {
        if ($columns == 2){
        $x1 = rand(1,8);
        $x2 = rand(0,8);
        $y1 = rand(1,9-$x1);
        $y2 = rand(0,9-$x2);
        } else {
        $x1 = rand(1,8);
        $y1 = rand(1,9-$x1);
        }
    }
    
    return $x1.$x2.$operator.$y1.$y2;
    }
    

    ex..

    31
    +54

    ..where
    3=$x1
    1=$x2
    5=$y1
    4=$y2

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

Sidebar

Related Questions

I have an existing site that requires a background image on the home page.
I have developed a web site that requires user registration and authentication for some
I am working on a site that requires a jquery Galleryview now I have
I am creating a site that requires a very small postcode checker. I have
I have a page on my site that I'm trying to test that requires
I have a Classic ASP site, that requires some database tables to be emptied
I have a site that requires users to enter days and times they would
I have a site that I'm planning to launch soon but it requires some
I have a section of my site that requires global data for a navigation
I'd like to programmatically access a site that requires Client certificates, which I have

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.