Documentation / LearningLemur

  • Demos
  • Visit our website
  • Contact us
  • MathType

    • WirisQuizzes

      • LearningLemur

        • CalcMe

          • MathPlayer

            • Store FAQ

              • VPAT for the electronic documentation

                • MathFlow

                  • BF FAQ

                    • Miscellaneous

                      • Wiris Integrations

                        • Home
                        • LearningLemur
                        • Using LearningLemur
                        • Advanced Logic in LearningLemur
                        • Advanced Logic Examples in LearningLemur
                        • Advanced Logic Examples in LearningLemur

                        How to generate two random irreducible fractions

                        Reading time: 1min

                        When to use this: Use this method when you want students to compute the sum of two fractions and ensure that each generated fraction is already irreducible (i.e., simplified before the operation).

                        What you'll achieve: You will generate two random fractions whose numerators and denominators are coprime, guaranteeing that both fractions are irreducible before students calculate their sum.

                        See it in action: Watch how this logic is implemented inside LearningLemur:

                        Your browser does not support HTML5 video.

                        Before you begin

                        Requirements

                        • Basic knowledge of how to create a LearningLemur question
                        • Familiarity with adding an algorithm to generate random variables

                        Steps

                        Generate the first numerator

                        a = random(1,9)

                        This defines the numerator of the first fraction.

                        Generate a compatible denominator

                        B = {b with b in 2..9 where gcd(a,b) = 1}
                        b = random(B)

                        This creates a set of denominators coprime to a, ensuring the fraction is irreducible.

                        Generate the second numerator

                        c = random(1,9)

                        Generate the second denominator

                        D = {d with d in 2..9 where gcd(c,d) = 1 && d != b}
                        d = random(D)

                        This ensures:

                        • The second fraction is irreducible
                        • The denominators are not identical

                        Define the solution

                        sol = a/b + c/d

                        This stores the correct answer for grading.

                        Verify it worked

                        • Preview the question multiple times
                        • Confirm that each generated fraction is already simplified
                        • Check that no denominator equals 0
                        • Ensure the sum is computed correctly

                        Full algorithm (copy-paste version)

                        Use the complete version below if you want to copy the logic directly into your question algorithm:

                        # Generate the first fraction
                        a = random(1,9)    
                        
                        B = {b with b in 2..9 where gcd(a,b) = 1}  
                        b = random(B)               
                        
                        # Generate the second fraction
                        c = random(1,9)   
                        
                        D = {d with d in 2..9 where gcd(c,d) = 1 && d != b} 
                        d = random(D)                  
                        
                        # Compute the solution
                        sol = a/b + c/d

                        Options and variations

                        • If you want to allow identical denominators, you can remove the condition d != b from the second denominator set
                        • If you want larger fractions, you can increase the interval (e.g., 1..15 instead of 1..9), but test performance to avoid excessive regeneration
                        • If you want to enforce simplified student answers, you can combine this pattern with answer validation constraints in grading logic

                        Common errors

                        Fractions are not irreducible

                        Check that gcd(a,b)=1 is correctly written in the set definition

                        Infinite regeneration loop

                        Ensure the denominator interval contains enough values to satisfy the coprimality condition

                        Unexpected duplicate fractions

                        Add additional constraints if you need both fractions to differ entirely

                        Related

                        • Understanding Advanced Logic in LearningLemur
                        • Common Patterns and Best Practices
                        • Glossary of Commands

                        Was this article helpful?

                        Yes
                        No
                        Give feedback about this article

                        Related Articles

                        • Greatest common divisor (gcd)
                        • Partial fractions
                        • Constant sequence

                        How to generate two random irreducible fractions

                        Before you begin Requirements Steps Generate the first numerator Generate a compatible denominator Generate the second numerator Generate the second denominator Define the solution Verify it worked Full algorithm (copy-paste version) Options and variations Common errors Fractions are not irreducible Infinite regeneration loop Unexpected duplicate fractions Related

                        Making people’s STEM work more meaningful

                        MathType

                        • MathType for Office Tools
                        • MathType for Mac
                        • MathType for Microsoft 365
                        • MathType for Google Workspace
                        • MathType for LMS
                        • MathType for XML Editors
                        • Arabic notation
                        • Our products accessibility
                        • MathType is online

                        WirisQuizzes

                        Learning Lemur

                        Solutions for Education

                        • Blackboard Learn
                        • Brightspace by D2L
                        • Canvas
                        • Google Classroom
                        • Moodle
                        • Schoology

                        Solutions for Publishing Houses

                        Solutions for Technical Writers

                        Solutions for Chemistry

                        Integrations

                        • HTML Editors
                        • MathType in WordPress

                        Pricing

                        Company

                        Careers

                        Blog

                        Contact Us

                        Buy Now

                        Plugin Downloads

                        © Wiris 2025

                        • Cookie Settings
                        • Cookie Policy
                        • Terms of Use
                        • Privacy Policy / GDPR
                        • Student Data Privacy
                        • Compliance
                        • Powered by Helpjuice
                        Expand