I can almost do it now... but not quite.
I made the code below which compiles, but does not separate the exercises from the solutions. I commented out the way I thought I could separate solutions and exercises, but that did not work unless I remove \Diagram from the definition of \Solution, meaning that there is some tikZ problem with \xdef... I think.
All the pictures and files are in this Dropbox folder. https://www.dropbox.com/sh/04uujszim2jr ... 2tTBa?dl=0
[Side note: I do not know how to turn normal text into a link, so I pasted that huge URL instead...]
Sorry for the long MWE; I'm not sure what I could remove and still get the point across! If anyone needs me to comment on any of the code, I'm happy to.

Code: Select all
Code, edit and compile here:
\documentclass{article}\usepackage[margin = 1.5cm, landscape]{geometry}\usepackage{graphicx}\usepackage{pgf}\pgfmathsetseed{\number\pdfrandomseed}\usepackage{pgffor}\usepackage{tikz}\setlength{\parindent}{0cm}\newcommand{\InitVariables}{ \pgfmathrandominteger{\Sets}{1}{10}\pgfmathrandominteger{\PerSet}{1}{10}\pgfmathsetmacro{\Total}{int(\Sets*\PerSet)}}\newcommand{\picturescale}{0.4}\newcommand{\Diagram}{}\newcommand{\ChosenPic}{}\newcommand{\Exercise}{}\newcommand{\Solution}{}\newcommand{\GenOneExerciseAndSolution}{\InitVariables\renewcommand{\Diagram}{\ifcase\PerSet\relax\or \renewcommand{\ChosenPic}{SetOfOne}\or \renewcommand{\ChosenPic}{SetOfTwo}\or \renewcommand{\ChosenPic}{SetOfThree}\or \renewcommand{\ChosenPic}{SetOfFour}\or \renewcommand{\ChosenPic}{SetOfFive}\or \renewcommand{\ChosenPic}{SetOfSix}\or \renewcommand{\ChosenPic}{SetOfSeven}\or \renewcommand{\ChosenPic}{SetOfEight}\or \renewcommand{\ChosenPic}{SetOfNine}\or \renewcommand{\ChosenPic}{SetOfTen}\fi