# Capturing previous random numbers

I’m using the random number generator in a repeated practice activity. I need the problem to remain when an explain prompt pops up, or use the previous random numbers to show up in my explain prompt. Is this an easy fix?

Check out how I did it in that activity from yesterday. I set a variable to equal the captured last value if the button is pressed, and if it’s not pressed, the same variable is equal to a new randomly generated number. Look at addend1 or addend2. If you have questions about specific parts of that code, let me know!

Yeah, I see how it works, but I changed to an percent of change activity with math input instead of a submit button, so I can’t figure it out.
After they hit submit, an explain prompt pops up that asks if it was an increase or a decrease. I briefly toyed with the idea of adding that code from the previous activity where they choose the button for increase or decrease, but it starts to get too complicated. Usually students don’t have difficulty identifying increase or decrease, so it doesn’t have to be checked, but I still want them to do it.

Funny things happen with the code when I paste it, though. I tried a number of things. r1 before submit, a1 after submit to capture the previous r1, but the “in.lastValue(“r1”) otherwise numericValue(`{\${r.int(1,20)}`)” isn’t right?

r = randomGenerator(in.submitCount)
r1 = r.int(1,20)
r2 = r.int(1,20)
a1 = when in.timeSinceSubmit>0 in.lastValue(“r1”) otherwise numericValue(`{\${r.int(1,20)}`)
a2 = when in.timeSinceSubmit>0 in.lastValue(“r2”) otherwise numericValue(`{\${r.int(1,20)}`)

value = P
P = numericValue("{p}*100") p = numericValue("\round( {d}, 2)")
d = numericValue("(\abs({r1} - {r2}))/\${r1}")

content:
when in.timeSinceSubmit() > 0 "{result}\n\n\Click to try another." otherwise " Find the percent of change from {r1} to \${r2}
Round to the nearest whole percent.
"

result = when in.lastValue(“correct”) = 1 "Correct!

Good! From {a1} to {a2} was a \${in.numericValue}% change.

" otherwise “Incorrect.”

It might be a little easier to troubleshoot if I have the link to the activity. I see a couple parts that might be causing a problem, but I don’t see what you have for your capture variables, so I’m don’t want to give you incorrect information.

Tossing in the multiple choice to check for increase or decrease is only a few more lines of code. Since I might be able to use this idea, I made an attempt at what you were looking for. Use it if you want, otherwise I can look at the code for the one you already have started too!

1 Like

This is exactly what I wanted and way better than what I was doing, so I can’t thank you enough.
Seriously, my heart is really big with gratitude right now.

1 Like