Message from @carlfink :
So you create 3 Lectora test objects. (They aren’t technically “objects” in the sense of OO programming, but let that go.) Say you name them test1, test2, and test3.
When the student reaches the “take a test” page, you can create OnShow actions that check the values for test1_score, test2_score, and test3_score. You’d need an action sequence to calculate the number of tests taken by incrementing a variable, e. g. in pseudocode: “if test1 is nonzero, tests_taken = tests_taken + 1” and the same for tests 2 and 3.
Now an action says, “If tests_taken = 2, force the user back to the beginning to retake the educational portion.” Another says, “if tests_taken = 3, the user has failed” and jumps to a page that handles failures.
Then another action after the calculation actions can pick a random test. Due to the limitations of the “variables with random initial values” feature of Lectora (there’s no convenient way to re-randomize the variable after the module initializes), I’d use a hidden text field, with an action OnPageShow to “Set Text >> RAND(1,3)” which sets its contents to an integer: 1, 2, or 3.
Since OnPageShow actions happen before the OnShow actions for the objects on the page, that should happen first. Now, determine if that test was already given, with a simple, “if the value is 1, AND test1_score is nonzero, THEN randomize again” and the same for 2 and 3.
Then you use a series of actions that say “If the contents of the field are 1 AND test1_score is nonzero, go to test 1. If the contents are 2 AND ….”.
Note that for this to work reliably, each test has to set its own score to some nonzero value as soon as the user reaches its first page. That can be as simple as on OnShow action setting testn_score to 1. When the test is scored, that will override the value of 1 with the score actually earned, but it would never go back to zero.
I haven’t built the module, but that should give you a skeleton of how to do it.