I have some code that generates some random content. I would like to add the ability to use the last-results instead of generating new random values. The way I thought to do this would be to 'save' the random numbers/results into a persistent location and load them under certain conditions (eg have some optional argument in the command generating the random values that allows you to flag whether you want to use the last results or generate new ones).
I know things like the \label and \ref systems do this, which is why you have to compile twice, so I was thinking about utilizing whatever system is working in the background with them. Unfortunately I've never tinkered with this part of LaTeX and have no idea what it is even called or where to look to find information about it. If anyone could at least point me in the right direction (or tell me it can't realistically be done) I'd appreciate it.
If it matters I typically prefer to work with LaTeX2 or LaTeX, but I have been (slowly) learning LaTeX3 so that's at least plausible as well. Thanks!

\getrefnumberfromrefcountfor this – Sep 06 '17 at 16:40ToCis described inhttps://tex.stackexchange.com/questions/273098/mimicking-latexs-table-of-contents-functionality/273106#273106, but the\label,\refapproach is the better one, in my point of view if it is done with expandable commands – Sep 06 '17 at 16:50