-
MathType
-
WirisQuizzes
-
LearningLemur
-
CalcMe
-
MathPlayer
-
Store FAQ
-
VPAT for the electronic documentation
-
MathFlow
-
BF FAQ
-
Miscellaneous
-
Wiris Integrations
How to generate two random irreducible fractions
Reading time: 1minWhen 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:
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/dThis 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/dOptions and variations
- If you want to allow identical denominators, you can remove the condition
d != bfrom the second denominator set - If you want larger fractions, you can increase the interval (e.g.,
1..15instead of1..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