This should give you a fairly good template:
Define a function that takes an ID and returns a suitably randomized graph of a line that includes some clearly labelled points.
lineProblemGeneratorPointsGiven[problemIDNum_] := Block[
{m, k, visibleDomain, shownXVals, shownPoints},
m = RandomChoice[Join[Range[-5, -1], Range[1, 5]]];
k = RandomInteger[{-5, 5}];
lineEq[x_] := m x + k;
visibleDomain = Clip[Sort[{(-20 - k)/m, (20 - k)/m}], {-20, 20}];
shownXVals = RandomSample[Range @@ IntegerPart[visibleDomain], 2];
shownPoints = ({#, lineEq[#]} & /@ shownXVals);
graphicForStudent = Plot[
lineEq[x],
{x, -20, 20},
PlotRange -> {{-20, 20}, {-20, 20}},
Frame -> True,
FrameStyle -> Bold,
GridLines -> Transpose[shownPoints],
Epilog -> {
PointSize[0.015], Red, Point[shownPoints],
Black, Text[Style[ToString[problemIDNum], 30], {-19.5, 17}, {-1, 0}]
},
FrameTicks -> {{Transpose[shownPoints][[2]], None}, {Transpose[shownPoints][[1]], None}}
];
{Rasterize[graphicForStudent, RasterSize -> 500], problemIDNum, m, k}
]
Now use it to generate a batch of problems:
my5Problems = lineProblemGeneratorPointsGiven /@ Range[5];
Now you want to export this so you have a folder of images and a spreadsheet of answers, so go ahead and make some directory lineProblemStorage. Include inside that one some directory imageStorage.
linePicsWithID = #[[1 ;; 2]] & /@ my5Problems;
Export[FileNameJoin[{lineProblemStorage, imageStorage, ToString[#[[2]]] <> ".jpg"}], #[[1]]] & /@ linePicsWithID
Now imageStorage contains the images to be given to the students. You need your answer sheet, though.
myAnswers = Join[{{"ID", "m", "k"}}, #[[2 ;; 4]] & /@ my5Problems];
Export[FileNameJoin[{lineProblemStorage, "answers.xls"}], myAnswers]
I seem to remember tests being averse to giving students labelled points when reading from graphs in order to prepare them for the real world where graphs are only used to communicate numerical minutiae of the function in question rather than to eyeball a solution for sanity or present themes and trends./s
If you want to be cruel and have your students strain their eyes and second guess themselves finding points that fall on the grid, you can use this generating function instead:
lineProblemGeneratorGridLines[problemIDNum_] := Block[
{m, k, visibleDomain, shownXVals, shownPoints},
m = RandomChoice[Join[Range[-5, -1], Range[1, 5]]];
k = RandomInteger[{-5, 5}];
lineEq[x_] := m x + k;
graphicForStudent = Plot[
lineEq[x],
{x, -20, 20},
PlotRange -> {{-20, 20}, {-20, 20}},
Frame -> True,
FrameStyle -> Bold,
GridLines -> {Range[-19, 19], Range[-19, 19]} ,
Epilog -> {Black, Text[Style[ToString[problemIDNum], 30], {-19.5, 17}, {-1, 0}]}
];
{Rasterize[graphicForStudent, RasterSize -> 500], problemIDNum, m, k}
]
Table
andMap
instead of trying a For loop.Table
will return a list of results that you can save into a variable for later export, printing etc. $\endgroup$