From WeBWorK_wiki
Revision as of 17:55, 11 November 2011 by Glarose (talk | contribs) (Created page with '<h2>Linking Successive Problems</h2> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> <em>This is the PG code to result in a problem having a predictable…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Linking Successive Problems

This is the PG code to result in a problem having a predictable set of variable values, so that one can link successive problems in a set "knowing" what the previous problem included.

Problem Techniques Index

PG problem file Explanation
$a = random(1,3,1);
$b = random(1,3,1);

Setup: To make the random values that show up in a problem be consistent between problems, two things need to happen: we need to set the random seed for the problems so that they are the same, and we need the sequence of calls to the random number generator to be the same in each of the problems.

We can do the first of these by calling SRAND; a value that is consistent for all problems in a set is the value of the psvn (Problem Set Version Number). Here we've set the seed for the random number generator to be the PSVN.

Then we just include all of the random calls that have been used in the preceding problems that have the same seed in the same order. Here we have the variables $a and $b.

In the previous problem you found
the value of \($a^2\).  Now find
\( $a^2 - $b = \) \{ ans_rule(5) \}


Main Text: In the text section of the problem we proceed as expected.

ANS( Compute("$a*$a - $b")->cmp() ); 


Answer evaluation: And the answer and solution section of the file is straightforward.

Problem Techniques Index