Wiris

Documentation / WirisQuizzes

  • 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
                        • WirisQuizzes
                        • Advanced Validation Features
                        • Advanced use of random variables
                        • Advanced use of random variables

                        Randomness in intervals and sets of numbers

                        Reading time: 2min

                        Sum of two random fractions

                        We will create a question asking the students for the sum of two random fractions. First, we need to write the algorithm of the question.

                        Tip

                        You can find more detailed information about how to create this question with the basic mode here.

                        The random command allows us to retrieve a random number in a given interval. We need four random numbers: two numerators and two denominators; that we will call a, b, c, and d (the name of the variables is essential). Let us write the code.

                        Now we have four random numbers between 1 and 9 (both included). We will also compute the sum of the fractions they define and store the result in a variable.

                        Once we have defined the algorithm, we write the solution in the Correct answer tab. Now it is not a number; it is a variable called sol. In order to write a variable anywhere outside CalcMe , we must precede the name of the variable with the pound sign #. Therefore, we will write #sol in the correct answer field.

                        Finally, once we have checked the question's behaviour in the Preview tab, we write the statement of the problem. Recall that our numerators and denominators were stored in variables called num1, num2, den1, and den2. In the same way, as in the Correct answer section, we have to write the name of the variables preceded by the pound sign #. Fractions can be written with MathType

                        Sum of two random irreducible fractions

                        Notice that the algorithm could generate some unwanted statements we have suggested above as

                        Where both fractions have the same denominator. We can avoid this situation with a simple change in our algorithm. We just have to exclude the first denominator value from the set of the second denominator possible values. Here we can see how the code will look like.

                        Furthermore, the initial algorithm could generate even more undesirable statements, as we can see in the following example.

                        In this case, the fractions that appeared in the statement are not simplified, and they can even be expressed in integer form. To prevent this situation, the values whose greatest common divisor with its numerator is different from 1 will be excluded from the set of possible denominator values. Here we can see how the code will look like.

                        Rounded and truncated random numbers

                        We will create a question asking the students to round to the tenth ones and truncate some random numbers to the hundredth ones. We will choose the embedded answers (Cloze) question type. Let's write the algorithm of the question.

                        Tip

                        You can find more detailed information about embedded answers (Cloze) here.

                        The random command allows us to retrieve a random number in a given interval. Actually, we can add an option, so just the interval numbers with a given step will be considered, as we will see below.

                        We need five numbers with three decimal digits each. Since it could result in a little bit tedious to write so many times that command, we will avoid it by defining a global function r():=random([0..10..0.001]). Let us write the code.

                        Caution

                        Notice the importance of using the sign := instead of = when defining the function r(). Otherwise, r() will always take the same value, and the five numbers will be the same. More detailed information about creating custom functions here.

                        For now, we have five real random numbers between zero and ten with three decimal digits. We also have to round them to the tenth ones and truncate them to the hundredth ones.

                        Note

                        Notice that we multiplied the rounded and truncated numbers by 1.0 , so the answers appear in decimal form instead of the rational form.

                        As we have written the algorithm, we can obtain some unwanted numbers which are already rounded at the tenth one or truncated at the hundredth one, as we can see in the example below.

                        To avoid this kind of situation, we can prevent numbers ended with 0 or 00 from being generated in the following way.

                        This way, we will only obtain appropriate numbers with three decimal digits, as we can see below.

                         

                        Was this article helpful?

                        Give feedback about this article

                        Related Articles

                        • Random variables section
                        • Single set
                        • Area of a random rectangle

                        Randomness in intervals and sets of numbers

                        Sum of two random fractions Tip Sum of two random irreducible fractions Rounded and truncated random numbers Tip Caution Note

                        Empowering STEM education

                        MathType

                        • Office Tools
                        • LMS
                        • XML
                        • HTML

                        WirisQuizzes

                        Learning Lemur

                        Integrations

                        Solutions

                        • Education
                        • Publishing houses – platforms and interactive
                        • Publishing houses – Print and digital
                        • Technical writers

                        Pricing

                        Downloads

                        Blog

                        • Success stories

                        About us

                        • Careers
                        • Partnership

                        Contact Us

                        Contact Sales

                        European union (European Regional Development Fund) and 1EdTech (TrustEd Apps Certified)
                        • Cookie Policy
                        • Terms of Use
                        • Privacy Policy / GDPR
                        • Student Data Privacy
                        • Compliance
                        • Cookie Settings

                        © Wiris 2026

                        Expand