Following this answer, the following document, many times, doesn't change the output each time I compile it. The output may change after three or four times I recompile the document.
So, how to change the randomization mechanism to make the output different from its previous version each time I compile the document?
\documentclass{exam}
\usepackage[randomize]{exam-randomizechoices}
\begin{filecontents}[overwrite]{bankA.tex}
\begin{questionblock}
\question[5] What is the result of $1+1$?
\begin{randomizechoices}
\choice 1
\CorrectChoice 2
\choice 3
\choice 4
\end{randomizechoices}
\end{questionblock}
\begin{questionblock}
\question[5] What is the result of $2+1$?
\begin{randomizechoices}
\choice 11
\CorrectChoice 3
\choice 31
\choice 14
\end{randomizechoices}
\end{questionblock}
\begin{questionblock}
\question[5] What is the result of $3+1$?
\begin{randomizechoices}
\choice 111
\CorrectChoice 4
\choice 31
\choice 411
\end{randomizechoices}
\end{questionblock}
\begin{questionblock}
\question[5] What is the result of $4+1$?
\begin{randomizechoices}
\choice 111
\CorrectChoice 5
\choice 113
\choice 114
\end{randomizechoices}
\end{questionblock}
\end{filecontents}
\usepackage{catchfile,environ,tikz}
\makeatletter% Taken from https://tex.stackexchange.com/q/109619/5764
\def\declarenumlist#1#2#3{%
\expandafter\edef\csname pgfmath@randomlist@#1\endcsname{#3}%
\count@@ne
\loop
\expandafter\edef
\csname pgfmath@randomlist@#1@\the\count@\endcsname
{\the\count@}
\ifnum\count@<#3\relax
\advance\count@@ne
\repeat}
\def\prunelist#1{%
\expandafter\xdef\csname pgfmath@randomlist@#1\endcsname
{\the\numexpr\csname pgfmath@randomlist@#1\endcsname-1\relax}
\count@\pgfmath@randomtemp
\loop
\expandafter\global\expandafter\let
\csname pgfmath@randomlist@#1@\the\count@\expandafter\endcsname
\csname pgfmath@randomlist@#1@\the\numexpr\count@+1\relax\endcsname
\ifnum\count@<\csname pgfmath@randomlist@#1\endcsname\relax
\advance\count@@ne
\repeat}
\makeatother
% Define how each questionblock should be handled
\newcounter{questionblock}
\newcounter{totalquestions}
\NewEnviron{questionblock}{}%
\newcommand{\randomquestionsfrombank}[2]{%
\CatchFileDef{\bank}{#1}{}% Read the entire bank of questions into \bank
\setcounter{totalquestions}{0}% Reset total questions counters ***
\RenewEnviron{questionblock}{\stepcounter{totalquestions}}% Count every question ***
\bank% Process file ***
\declarenumlist{uniquequestionlist}{1}{\thetotalquestions}% list from 1 to totalquestions inclusive.
\setcounter{totalquestions}{#2}% Start the count-down
\RenewEnviron{questionblock}{%
\stepcounter{questionblock}% Next question
\ifnum\value{questionblock}=\randomquestion
\par% Start new paragraph
\BODY% Print question
\fi
}%
\foreach \uNiQueQ in {1,...,#2} {% Extract #2 random questions
\setcounter{questionblock}{0}% Start fresh with question block counter
\pgfmathrandomitem\randomquestion{uniquequestionlist}% Grab random question from list
\xdef\randomquestion{\randomquestion}% Make random question available globally
\prunelist{uniquequestionlist}% Remove picked item from list
\bank% Process file
}}
\begin{document}
\begin{questions}
\randomquestionsfrombank{bankA.tex}{2}
\end{questions}
\end{document}