Documentation / LearningLemur

  • Demos
  • Visit our website
  • Contact us
  • MathType

    • WirisQuizzes

      • Learning Lemur

        • CalcMe

          • MathPlayer

            • Store FAQ

              • VPAT for the electronic documentation

                • MathFlow

                  • BF FAQ

                    • Miscellaneous

                      • Wiris Integrations

                        • Home
                        • Learning Lemur
                        • Using Learning Lemur
                        • Advanced Question Logic
                        • Advanced Question Logic

                        How to generate two random irreducible fractions

                        Reading time: 2min

                        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 Learning Lemur:

                        Your browser does not support HTML5 video.

                        Before you begin

                        Requirements

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

                        Steps

                        Generate the first numerator — Select a random value

                        a = random(1,9)

                        This defines the numerator of the first fraction.

                        Generate a compatible denominator — Ensure coprimality

                        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 — Select a new random value

                        c = random(1,9)

                        Generate the second denominator — Ensure coprimality and avoid duplication

                        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 — Compute the sum

                        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: Remove the condition d != b from the second denominator set
                        • If you want larger fractions: 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: 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

                        • Reference: [feature/settings]
                        • Explanation: [concept]

                        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 — Select a random value Generate a compatible denominator — Ensure coprimality Generate the second numerator — Select a new random value Generate the second denominator — Ensure coprimality and avoid duplication Define the solution — Compute the sum Verify it worked Full algorithm (copy-paste version) Options and variations Common errors 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