1. LON-CAPA Logo
  2. Help
  3. Log In
 

Static and Dynamic

Back to Index

What are static and dynamic problems? A static problem is a problem that will always be the same, whereas a dynamic problem is generated differently each time from the blueprints you write with code directly or indirectly using random numbers to set the pieces that change.

The largest benefit to having dynamic problems is that when you create a dynamic problem, it can be used many times. You are able to give a student the same dynamic problem multiple times with the student receiving a different question every time, which means that dynamic problems are reusable. This also makes it more difficult to cheat on tests.

Dynamic problems generally only take slightly longer to make than their static versions, so in most if not all cases dynamic problems are preferred.

The previous example, 2+2=4, is static since each number is the same each time. To make this problem dynamic, you would simply turn each number into variable. For instance, a+b=c is a dynamic version of this problem. After you have these variables, simply set them to a random number within your predetermined limits. For this problem, we will set a and b to random integers between 1 and 12. The following are the changes needed to change this example from static to dynamic.

<problem>
 <script type="loncapa/perl">
  $number1 = &random(1,12,1);
  $number2 = &random(1,12,1);
  $ans = $number1 + $number2;
 </script>
 <startouttext />
  What is <m eval ="on">$ $number1 + $number2$</m>?
 <endouttext />
 <numericalresponse answer=$ans>
 <textline />
 </numericalresponse>
</problem>

The first big change is the <script>. Scripts are the meat of dynamic problems as they control how the problems are generated.

<script type="loncapa/perl">
 $number1 = &random(1,12,1);
 $number2 = &random(1,12,1);
 $ans = $number1 + $number2;
</script>

  1. <script type="loncapa/perl">
  2. Creates the script that uses Perl, which is a programming language that is supported by LON-CAPA.

  3. $number1 = &random(1,12,1);
  4. This creates a variable (signified by the character $ and the name for the variable) and sets its value. The value on the left side of the = is always set by the value on the right. This is true also in other situations, like in our previous code where answer="4" set answer to 4.

    If a variable on the left doesn’t exist, then it is created. If it does, then the old value of that variable is replaced.

    On the other side, we have &random(1,12,1);. This returns an integer from 1 to 12 and sets it to number1. Random functions are explained in detail in the Perl section.

    In Perl (as well as many other programming languages) the character “;” signifies that you have ended your instruction. This is similar to the “/” in xml documents.

  5. $number2 = &random(1,12,1);
  6. Creates a second variable.

  7. $ans = $number1 + $number2;
  8. You are also able to use arithmetic operators on variables on the right side of the “=”. In this case, these operations are completed before the variable value is set.

  9. </script>
  10. The script is over. However, the variables are still saved to the problem and can be accessed at a later time.

  11. What is <m eval ="on">$ $number1 + $number2$</m>?
  12. When setting eval to on in <m>, you are able to place variables denoted with a $ inside the <m></m> tags. Since these numbers are at this point set to their values, when problem writes these numbers to the screen they will contain the values of a and b.

  13. <numericalresponse answer=$ans>
  14. This changes the answer from static 4 to the dynamically calculated value of $ans

Back to Index