3

Suppose I want to design a math exam to be posted as a single PDF file, for example one asking students to solve $ax^2+bx+c=0$. But I want each student who gets the PDF file to see a different set of $a,b,c$ values upon opening their files. Is such a thing possible?

For example, can a random seed that is taken from the time of opening of the file or some factor related to the computer of the recipient set the values of $a,b,c$?

And in addition, I prefer that the seed is generated only once, so that on the second reopening of the same file the student sees what s/he saw the first time. Is this possible?

What is the preferred/easier alternative to PDF?

EDIT:

I realized that the scheme is not safe. In the sense that a student can write any convenient $abc$ and claim that that is the random number generated for him!

So here is a modification: Student enters his ID number in a form field and presses a button. Out comes $a,b,c$. This will be reproducible and each student gets a different set and upon reloading the same numbers will show.

Would the resulting PDF be a security issue or one that will exhibit many compatibility problems?

Maesumi
  • 9,059
  • 4
    It is possible to make from one (1) exam source more than one hundred (>100) exams in a single PDF, were in each exam copy the equation is randomly different, but the only way to change the PDF contents is compiling again. If this is acceptable for you, see this simple example of AMC. – Fran Feb 13 '21 at 01:53
  • 6
    If you are prepared to use JavaScript and Adobe reader you can use form fields. But this will not give you nice maths. I don't think this is a good option though. – David Purton Feb 13 '21 at 02:52
  • @Fran in the answer you have linked to there is a package called "automultiplechoice". I do not see it listed under packages on MiKTeX. – Maesumi Feb 13 '21 at 21:27
  • @Maesumi AMC Is not only a package, is not in CTAN. See here. And is not for Window, but see here for alternatives. – Fran Feb 13 '21 at 21:44
  • @DavidPurton An edit is made to the question. Does this work JavaScript? – Maesumi Feb 17 '21 at 14:57
  • 1
    Each student must buy Adobe Acrobat Pro in order to process your PDF? – wipet Feb 18 '21 at 07:20

3 Answers3

2

Take a look at random.tex which enables generation of random numbers. A simple example:

\documentclass{article}
\input{random}
\begin{document}
\nextrandom  % generate a random number as \randomi
\the\randomi % print the random number
\end{document}

Read the manual texdoc random for more information.

EDIT

I suggest that you run LaTeX on your file once for each of your students. They will then get a PDF file with unique random numbers. 15 students you generate 15 PDF files. You would need to record to which students you sent their unique PDF file.

Peter Wilson
  • 28,066
  • 2
    With this approach, the random number gets generated when the pdf is created and then remains fixed. If I understand the OP correctly, the question is whether the number can be generated anew each time the pdf is opened. – gernot Feb 13 '21 at 18:44
  • @gernot As I understand it the OP's problem could be resolved by getting each student to run LaTeX on the source file to produce their PDF with unique random numbers. Otherwise the question is directed at PDF viewers. Person A views a PDF file which has a random number and person B views the "same" PDF file with a different random number but if A later views the PDF file it has the same random number when viewed previously. I have no idea if this is possible; have you? – Peter Wilson Feb 14 '21 at 18:59
  • I don't know the pdf format very well, so I can't answer the original question. The comment by David Purton hints at JavaScript in PDF forms as a (fragile) solution. – gernot Feb 14 '21 at 19:50
1

Here's a solution using the eforms package. This isn't part of TeXLive, but is in MikTeX. It's possible to get it from CTAN and install it in your local TeX tree if you're using TeXLive.

I think you'll need to write your own random number generator so that you can seed it with a student number. I used code from here.

This isn't very sensitive to the seed, so you would want to adjust how you get the final numbers or use a more suitable random number generator. I'm not really a maths guy, so this is left as an exercise for the reader…

This will only work with Adobe Reader. Virtually no other PDF viewer supports JavaScript.

To use it, enter a student number (e.g., 987654) and click the button. You'll get the same three numbers each time. If you enter a different student number, you'll get a different set of three numbers.

\documentclass{article}

\usepackage{parskip} \usepackage{eforms}

% Pseudo random number generator code taken from % https://stackoverflow.com/a/47593316/12652399 \begin{defineJS}{\genNums} function sfc32(a, b, c, d) { return function() { a >>>= 0; b >>>= 0; c >>>= 0; d >>>= 0; var t = (a + b) | 0; a = b ^ b >>> 9; b = c + (c << 3) | 0; c = (c << 21 | c >>> 11); d = d + 1 | 0; t = t + d | 0; c = c + t | 0; return (t >>> 0) / 4294967296; } } var txtId = this.getField("txtId"); var seed = Number(txtId.value) ^ 0xDEADBEEF; var rand = sfc32(seed, seed, seed, seed); var txtA = this.getField("txtA"); var txtB = this.getField("txtB"); var txtC = this.getField("txtC"); txtA.value = rand(); txtB.value = rand(); txtC.value = rand(); \end{defineJS}

\begin{document}

Student number: \textField{txtId}{3cm}{11bp} \pushButton[\CA{Generate Numbers}\A{\JS{\genNums}}]{btnRun}{}{11bp}

a: \textField{txtA}{5cm}{11bp}

b: \textField{txtB}{5cm}{11bp}

c: \textField{txtC}{5cm}{11bp}

\end{document}

output

David Purton
  • 25,884
  • Great! By the way, regarding the random number generator, I just noticed as I change the student number slightly the random number changes slightly. Which is odd. But that is a separate issue. – Maesumi Feb 19 '21 at 20:02
  • @Maesumi, yes that's what I mean when I say the random numbers are not very sensitive to the seed. But I don't have the maths to know the right kind of random number generator. – David Purton Feb 20 '21 at 03:07
0

I write multiple letters including deductions which depend on the addressee of the letter. To that end I use one letter and get different data via the datatool package. If you have 100 students you need probably not 100 different, but maybe 50 different sets of questions.

Keks Dose
  • 30,892